Elliot B.
Elliot B.

Reputation: 17681

preg_match on a number between variable whitespace and a fixed string

I'm trying to come up with a regular expression that will qualify on the 25 in this string:

Always       -       25 (Lifetime

The amount of space between the - and the 25 can be variable, but the trailing (Lifetime will always be there.

I've tried this: preg_match('/\s(.*)\s\(Lifetime',$sString,$aMatch); but it qualifies on the 25 and everything preceding it.

Upvotes: 2

Views: 381

Answers (1)

smottt
smottt

Reputation: 3330

Try the following:

preg_match('~\s+(\d+)\s\(Lifetime~', $sString, $aMatch);

It matches one or more space characters, followed by a number and finally the (Lifetime string.

Upvotes: 4

Related Questions