Skip to content
Advertisement

Tag: regex

str_contains returns true, but preg_match returns false

I am getting the HTML code of this website – https://theatrevazrajdane.bg/%D1%82%D0%B2%D0%BE%D1%80%D1%87%D0%B5%D1%81%D0%BA%D0%B8-%D1%81%D1%8A%D1%81%D1%82%D0%B0%D0%B2/%D0%B0%D0%BA%D1%82%D1%8C%D0%BE%D1%80%D0%B8/2 with this code $html = file_get_contents($url) and then I am running a simple regex which does not work and I have no idea why. This code output – FALSE and this code output – TRUE Do you know where it could be the reason I checked the HTML several

Finding all 1 digit and 2 digits numbers in a larger number using regex

I want to match all 1 digit and 2 digit numbers using regex. Subject string: ‘12345’ Expected match: 1,2,3,4,5,12,23,34,45 I’m trying: d(d)? but as result i get 12,2,34,3,5 Answer You can use See the PHP demo. Output: NOTES: (?=((d)d?)) – a regex that captures into Group 1 two or one digits, and into Group 2 the first digit of the

This regex works on regex101 but not in my script, why?

I have this regex: Which is not working as it should, see this code: I wrote my regex using this and it is working fine, until i add the regex to my script. https://regex101.com/r/EmebOT/1 If i replace [aàâ] with “â” in the regex so the regex looks like this, it works: Answer I got this working with use of the

Regex to find repeated sentences from more to less

i have string like $string = “hello this is a string and hello but this is a string hello but this is a string and “; in it there is repeated words and repeated sentences but i only want the sentences so i expect hello but this is a string to be captured i tried using this regex (.{10,}).*?1 but

How to pass the parameters properly for a callback function for preg_replace_callback using a preexisting function?

I am getting this error: Parse error: syntax error, unexpected ” (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)……… eval()’d code on line 2 Since removing e from the regex expression ~<IF (.?)(?<!-)>(.?)~se as shown in the line below because it became deprecated. I understood I need to use preg_replace_callback() and rewrite using an anonymous function however I

Advertisement