Domanda

I'm working on this regex:

/\{(\w+)::(\w+)::([\sa-zA-Z0-9]+)\}/

So, from a long string, I could get patterns like: Word::Word::Word and word and word

I've tested this regex here: http://regex101.com/

And in PHP it sais it should work fine.

But when I put into code, it doesn't work:

$pattern = '/\{(\w+)::(\w+)::([\sa-zA-Z]+)\}/';

echo preg_match_all(preg_match_all($pattern,'{WORD::WORD::PRUEB ASDF ASD}', $expr,PREG_PATTERN_ORDER));

the echo result is 0

È stato utile?

Soluzione

You are calling preg_match_all inside preg_match_all. Do this instead:

$pattern = '/\{(\w+)::(\w+)::([\sa-zA-Z]+)\}/';
echo preg_match_all($pattern,'{WORD::WORD::PRUEB ASDF ASD}', $expr, PREG_PATTERN_ORDER);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top