Re: Regular expression, (preg_split etc...), some help please.
"Sims" <siminfrance@ho tmail.com> wrote in message news:<c0gtip$17 dv70$1@ID-162430.news.uni-berlin.de>...[color=blue]
>
> $string = 'a1a ,2b , 3c, " 4, \"aaa, 5", 7';
> preg_match_all( '`(?<=").*?(?=( ?<!\\\)")|\d+`s ', $string, $array);
> print_r( $array );
>
> i get an output like...
>
> Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4, \"aaa, 5 [4]
> => 7 ) )
>
> Why are some of the letters ignored?
>[color=green]
> > Describing it at a high-ish level, the pattern looks for either of
> > two alternatives: zero or more quoted substrings, or one or more
> > decimal digits. A quoted substring, intuitively, begins and ends
> > with double-quotes.[/color]
>
> What part looks for a decimal number?
> I am afraid that my description should not have included numbers only.
> I want the RegEx to work for anything.
>
> so that a case like
>
> $string = 'xx,xx , xx," x, \"x, x", " x, x", xx, "xx", x';
>
> would work regardless what 'x' represents a letter, a number or a symbol,
> (apart form x= " itself).
>[/color]
Modify your RegExp according to following example.
I hope now you will get the expected result.
[SNIP]
$str = '1," 2 ,\" 3aaa", 4, 5';
$arr = preg_match_all( '#(?<=")\s*[\d]+.*[^\\\](?=")|[\d]+#U',$str,$matc hes);
print_r($matche s);
[/SNIP]
--
Cheers,
Rahul Anand
"Sims" <siminfrance@ho tmail.com> wrote in message news:<c0gtip$17 dv70$1@ID-162430.news.uni-berlin.de>...[color=blue]
>
> $string = 'a1a ,2b , 3c, " 4, \"aaa, 5", 7';
> preg_match_all( '`(?<=").*?(?=( ?<!\\\)")|\d+`s ', $string, $array);
> print_r( $array );
>
> i get an output like...
>
> Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4, \"aaa, 5 [4]
> => 7 ) )
>
> Why are some of the letters ignored?
>[color=green]
> > Describing it at a high-ish level, the pattern looks for either of
> > two alternatives: zero or more quoted substrings, or one or more
> > decimal digits. A quoted substring, intuitively, begins and ends
> > with double-quotes.[/color]
>
> What part looks for a decimal number?
> I am afraid that my description should not have included numbers only.
> I want the RegEx to work for anything.
>
> so that a case like
>
> $string = 'xx,xx , xx," x, \"x, x", " x, x", xx, "xx", x';
>
> would work regardless what 'x' represents a letter, a number or a symbol,
> (apart form x= " itself).
>[/color]
Modify your RegExp according to following example.
I hope now you will get the expected result.
[SNIP]
$str = '1," 2 ,\" 3aaa", 4, 5';
$arr = preg_match_all( '#(?<=")\s*[\d]+.*[^\\\](?=")|[\d]+#U',$str,$matc hes);
print_r($matche s);
[/SNIP]
--
Cheers,
Rahul Anand
Comment