[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    [PHP] Re: Regular Expression to get the whole Comma Separated String in Array Key
From:       201.22.6.221
Date:       2010-06-30 14:23:02
Message-ID: 4B.5E.54966.A435B2C4 () pb1 ! pair ! com
[Download RAW message or body]

Not tested, but I think it should work:

preg_match_all('/(\d+),/', $postText, $matches);

-- 
João Cândido de Souza Neto

"Gaurav Kumar" <kumargauravjukebox@gmail.com> escreveu na mensagem 
news:AANLkTikDb_ISmNkPoMicXzsfZIxg4deDzNuNrcimjud6@mail.gmail.com...
> Hi All,
>
> Need help in resolving the below problem-
>
>
> I would like to get the whole comma separated string into an array value-
>
> 1. $postText = "chapters 5, 6, 7, 8";
> OR
> 2. $postText = "chapters 5, 6;
> OR
> 3. $postText = "chapters 5, 6, 7";
>
> What i have done so far is-
> preg_match('/chapter[s]*[ ]*(\d+, \d+, \d+)/i', $postText, $matches);
>
> The above will exactly match the third value $postText = "chapters 5, 6, 
> 7";
>
> By Above $matches will contain a value of : $matches[1] = '5, 6, 7';
>
> Now i need a SINGLE regular expression which can match first, second
> variable above or any number of comma separated string and IMPORTANTLY
> provide me that whole comma separated sting value (as above) in single 
> array
> key element like below-
>
> $matches[1] = '5, 6, 7';
> OR
> $matches[1] = '5, 6';
> OR
> $matches[1] = '5, 6, 7, 8, 9';
>
>
> Also I have to use regular expression only as the flow of the code does 
> not
> permit to use any other method to get comma separated string from the
> master/base string.
>
> Thanks,
>
> Gaurav Kumar
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic