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

"blublu" [regexp] Extraire deux chaines : "blabla"[espaces,tab] - C#/.NET managed - Programmation

Marsh Posté le 06-08-2006 à 12:30:46    

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:

Reply

Marsh Posté le 06-08-2006 à 12:30:46   

Reply

Marsh Posté le 06-08-2006 à 12:35:38    

String.Split()


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

Marsh Posté le 06-08-2006 à 12:41:06    

: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 ?

Reply

Marsh Posté le 06-08-2006 à 12:45:48    


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
Reply

Marsh Posté le 06-08-2006 à 12:51:50    

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)

Reply

Marsh Posté le 06-08-2006 à 13:35:08    

"(.+?)"\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
Reply

Marsh Posté le 06-08-2006 à 13:36:17    

masklinn a écrit :

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


 [:haha]


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

Marsh Posté le 06-08-2006 à 13:49:17    


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
Reply

Marsh Posté le 06-08-2006 à 13:50:46    

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)
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed