problem with regex preg_match php

0

Good day to all, I have all day trying to solve how I do to find a match, for example, I have this chain

$txt='1a.10.2a.210.22ac.23acd.24acd'

I must validate that the value 23 is found, next to the letter C for example, but EVERYTHING among the "." the problem is that I deal with the following

preg_match('/(23).*?(c)/', $txt, $output_array);

It does not work, because even if you erase the letter C staying this way

$txt='1a.10.2a.210.22ac.23ad.24acd'

Like the letter C, it is in 24acd , it still finds a match. In summary, you only need to evaluate between the points (.), If the number you enter to search is not found next to the letter or at least between the points (.), It means that you did not find anything.

    
asked by Seguis Rafael 02.11.2018 в 00:07
source

1 answer

0

Try the following: 23[^.]*c

So, instead of using . , which would allow any character, you use [^.] which means "any character except the point". In this way you avoid "jumping" to the next group.

Demo

    
answered by 02.11.2018 / 09:52
source