Skip to content
Advertisement

Tag: regex

Replace a string that matches a pattern using preg_replace_callback

I want to replace the occurrences of the pattern “binary_function([x,y])” with substring “XY” in a given string. I have it working with the following code: However, I also want it to replace “binary_function([x1,y1])” with substring “X1Y1”, and any length of the arguments inside the square brackets e.g. [x11,y12], [var1,var2], etc. I tried this: but it did not work. Can anyone

regex to detect trailing comma and/or space separated numbers [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago. Improve this question I need a regex to detect and match some values like that: but values like following, are not allowed: One

Regex pluck parts too, not whole string

This is my input content: and this is regex example: This is the $matches content: Not bad, but I’d like somehow to pick “add_to_cart” and “product_name” as well. I can do it with explode() function, but wonder if there is a way to do this by regex only once. Also, I wonder if it is possible to have ‘target’ these

Regex for Group Links For WhatsApp URL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about programming within the scope defined in the help center. Closed 1 year ago. Improve this question I am using the following regex for validating Group Links For WhatsApp url’s. I want the regex to support the following

PHP regular expression start and end with given number [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question I have a string like this 202009170439051466017152d0bd457094b54f32eb029c4e9111725 I need to select the 1466017152 from that. (start with 146 and ending

PHP 7.4 PCRE2 newline character warning

Been testing a codebase migration from 7.3 to 7.4, and the only thing that affected us is the PCRE update under PHP. Currently this regex: /(>)([Rsvh]*)((&|#)?nbsp;|(&|#)nbsp)*([Rsvh]*)(<)/ Throws a nasty warning: Compilation failed: escape sequence is invalid in character class at offset 7 And indeed, if I remove the R, the warning disappears, but of course the behaviour changes. I have

Advertisement