Brideo
Brideo

Reputation: 163

Preg Match issues

I've been stuck with a fairly simple preg_match for a while and was wondering if someone could help me out.

Here is what im trying to do.

$string = 'Sub Total£24.00Shipping£5.95Grand Total£29.95Email:';
$m = preg_match('/Shipping(.*?)\Grand/s', $string, $match);

the array $match is returning empty and I really cant understand why.

Upvotes: 1

Views: 52

Answers (2)

DAG
DAG

Reputation: 6994

The \G token is the "last match" position anchor (like in PERL).

You need to esacape it:
\\G

More info:

The anchor \G matches at the position where the previous match ended. During the first match attempt, \G matches at the start of the string in the way \A does.

Source: http://regular-expressions.mobi/continue.html

Upvotes: 2

Andy Lester
Andy Lester

Reputation: 93815

It looks like you shouldn't have the \ before Grand. The sequence \G must mean something.

Upvotes: 0

Related Questions