Page 1 of 1

Help with Reged

Posted: Sat Jul 24, 2010 3:38 pm
by rlobianco
Hi,I'm trying to pull a purchase order number from the following string..

"Reseller PO - 23213123-123-232331"

All I need is the number. I tried (Reseller PO\s*-.\A*) it works with one online regex tester but not some others so I must have something wrong..

Help... :)

Re: Help with Reged

Posted: Sat Jul 24, 2010 4:45 pm
by AbraCadaver
Dunno why you're using \A, but this should work if the strings are consistent:

[text]/Reseller PO - ([-\d]+)/[/text]

Re: Help with Reged

Posted: Sat Jul 24, 2010 6:02 pm
by rlobianco
That syntax seems to pull the entire string..I need to just pull the number after the dash. The number can vary greatly though, Some are in the format I posted and some are just number with no dashes. I thought the \A would start the capture at the number.

Regards,
Ralph

Re: Help with Reged

Posted: Sat Jul 24, 2010 9:37 pm
by AbraCadaver
rlobianco wrote:That syntax seems to pull the entire string..I need to just pull the number after the dash. The number can vary greatly though, Some are in the format I posted and some are just number with no dashes. I thought the \A would start the capture at the number.

Regards,
Ralph
It depends upon what language you're using and how it returns matches. You should be able to pull the match for the first capture group (). In PHP it would be $matches[1] for this:

Code: Select all

preg_match('/Reseller PO - ([-\d]+)/', $search_string, $matches);
[text]Array
(
[0] => Reseller PO - 23213123-123-232331
[1] => 23213123-123-232331
)[/text]
And an array in $matches[1] for this:

Code: Select all

preg_match_all('/Reseller PO - ([-\d]+)/', $search_string, $matches);

Code: Select all

Array
(
    [0] => Array
        (
            [0] => Reseller PO - 23213123-123-232331
        )
    [1] => Array
        (
            [0] => 23213123-123-232331
        )
)