In PHP I am trying to create a regex without success, which should match expressions consisting of numbers and a single 'end'character, only of the numbers are not preceeded by an F. Here is an exmaple string to match
$test = "123A456C789XF765S333333AF444G";
and the following regex
preg_match_all("/(?<!F)(\d+)([ASTCGX])+/", $test, $matches)
finds the following expressions:
123A
456C
789X
65S
33333A
44G
while I expect only the following matches:
123A
456C
789X
333333A
I do not want to have the numbers \d+ split up to match the regex. An expression like F\d+[ACXSG]+ should not be matched! How to achieve this?
I suggest you to use this:
preg_match_all("/(?<![\dF])(\d++)([ASTCGX])/", $test, $matches);
explanation:
(?<![\dF]) # not preceded by F or a digit (numbers can't be trunked)
\d++ # one or more digit (with a possessive quantifier, optional but better)
[ASTCGX] # one of these characters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With