Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1189 connectés 

  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  [regexp] Extraire deux chaines : "blabla"[espaces,tab]"blublu"

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[regexp] Extraire deux chaines : "blabla"[espaces,tab]"blublu"

n°1420763
phenxdesig​n
Posté le 06-08-2006 à 12:30:46  profilanswer
 

Bonjour, je souhaite extraire 2 chaines entre guillemets, separées par des espaces ou des tabulations, en C#, avec des regexp, j'ai cherché, fait des essais, mais je suis arrivé à rien de bien :(
auriez vous une solution en tete ?  :jap:

mood
Publicité
Posté le 06-08-2006 à 12:30:46  profilanswer
 

n°1420765
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 06-08-2006 à 12:35:38  profilanswer
 

String.Split()


---------------
J'ai un string dans l'array (Paris Hilton)
n°1420769
phenxdesig​n
Posté le 06-08-2006 à 12:41:06  profilanswer
 

:D
j'y avais pensé, mais j'avais pas trouvé le truc :(
on peut le faire avec ça et ensuite prendre le 1er et le 3eme morceau ?

n°1420770
moi23372
Posté le 06-08-2006 à 12:45:48  profilanswer
 


et tu auras tout les mots dans chaques index du tableau.
 
string tonString = "blablabla blublublubul fsdfsdfdsfsdf fdsfsdfdsfsd";
string[] ch = tonString.Split(' ');
 
for (int i=0 ; i < ch.Length ; i++)
{
     MessageBox.Show(ch[i]);
}
 
et le tour est joué....
 
ça t'affichera
blablabla  
blublublubul  
fsdfsdfdsfsdf  
fdsfsdfdsfsd


Message édité par moi23372 le 06-08-2006 à 12:47:35
n°1420774
phenxdesig​n
Posté le 06-08-2006 à 12:51:50  profilanswer
 

nickel :)
 
tokens = buffer.Split('"');
if (tokens.Length == 5)
 listBox1.Items.Add(tokens[1]);
 
merci ! :jap:
 
(version juste d'essai, ça fait pas grand chose pour le moment :p)

n°1420798
masklinn
í dag viðrar vel til loftárása
Posté le 06-08-2006 à 13:35:08  profilanswer
 

"(.+?)"\s+"(.+?)" [:dawa]


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
n°1420799
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 06-08-2006 à 13:36:17  profilanswer
 

masklinn a écrit :

"(.+?)"\s+"(.+?)" [:dawa]


 [:haha]


---------------
J'ai un string dans l'array (Paris Hilton)
n°1420804
masklinn
í dag viðrar vel til loftárása
Posté le 06-08-2006 à 13:49:17  profilanswer
 


Cette RE fonctionne très bien si ton langage gère les PCRE [:dawa]
 
Demo:
Python

Code :
  1. >>> import re
  2. >>> matcher = re.compile('"(.+?)"\s+"(.+?)"')
  3. >>> matcher.match('"blublu"        "bmabla"').groups()
  4. ('blublu', 'bmabla')
  5. >>> matcher.match('"This is the rythm" "of the night"').groups()
  6. ('This is the rythm', 'of the night')
  7. >>> matcher.match('"Harko est un"    "gros phenos"').groups()
  8. ('Harko est un', 'gros phenos')
  9. >>>


JS

Code :
  1. > '"Harko est un" "phenos"'.match(/"(.+?)"\s+"(.+?)"/)
  2. "Harko est un" "phenos",Harko est un,phenos
  3. > '"This is the rythm" "of the night"'.match(/"(.+?)"\s+"(.+?)"/)
  4. "This is the rythm" "of the night",This is the rythm,of the night


Ruby

Code :
  1. irb(main):014:0> /"(.+?)"\s+"(.+?)"/.match('"Harko est un" "phenos"').to_a
  2. => ["\"Harko est un\" \"phenos\"", "Harko est un", "phenos"]
  3. irb(main):015:0> /"(.+?)"\s+"(.+?)"/.match('"blublu"        "bmabla"').to_a
  4. => ["\"blublu\"        \"bmabla\"", "blublu", "bmabla"]
  5. irb(main):016:0>


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
n°1420806
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 06-08-2006 à 13:50:46  profilanswer
 

un langage/framework bien foutu propose toujours des fonctions qui permettent de limiter l'usage des regex :o


---------------
J'ai un string dans l'array (Paris Hilton)

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  [regexp] Extraire deux chaines : "blabla"[espaces,tab]"blublu"

 

Sujets relatifs
extraire un midi d'un .exeExtraire du texte entre balise d'un .txt et generer html avec ce texte
Access:extraire des données à partir de HTML[FOP/PDF] comment extraire le PDF en tant que String, pour copier ?
date et php : extraire le mois d'une date SQL (debutant)Extraire une partie d'une chaine de caractère
[Résolu]extraire un fichier .zip en vba?Verifier numero de portable avec les RegExp
[PHP] Aperçu de fichiers - Extraire données fichier Excel[RegExp] Détecter toutes les adresses URL d'une chaîne de caractères
Plus de sujets relatifs à : [regexp] Extraire deux chaines : "blabla"[espaces,tab]"blublu"


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)