Escape from regex in php

Asked

Viewed 77 times

1

local-config_form_settings-test To match the "test", I’m using this regex:

(?<=config_form_settings-)([a-z0-9]+)

I tested the regex here: https://regex101.com/ And it’s just the way I want it. In php I am using preg_quote to give escape in the capture groups:

if (preg_match(preg_quote("(?<=peerreview_form_settings-)([a-z0-9]+)"), $result['name'], $matches) == true) {
  print("Match");
}

But this way do not match at all. Does anyone know the problem with regex?

1 answer

2


if (preg_match(preg_quote("(/?<=peerreview_form_settings-)([a-z0-9]+)/"), $result['name'], $matches) == true) {
  print("Match");
}

The indicator was missing / to indicate the beginning and end of the regular Expression.

  • Thanks for the help, buddy, that’s right

  • "should"? I use ~, #, @.

  • Corrected, @Guilhermelautert thanks for the indication.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.