1

I'm having trouble matching specific string using backtracking.

Here is the example strings to be matched.

 - Warning</b>:  include(db.inc.php) [<a
   href='function.include'>function.include</a>]:
 - Warning</b>:  mysql_real_escape_string() [<a   
   href='function.mysql-real-escape-string'>function.mysql-real-escape-string

Regex:

 warning<\/b>\:\s++(.*)\(.*?\)\s\[<a\shref='(function.\1)'>\2/m

The above regex would match the first example, but it will fail for the second example. As the first capture group with more than one word "mysql_real_escape" will have "_" in between.

Is there any way that I can replace "_" in \1 with "-" before matching.

Regex engine: PCRE

  • I think there is no way, you have to replace underscores with hypens or viceversa. – horcrux Mar 21 '17 at 10:04
  • 2
    You can't, but it is possible to check if each part separated with underscores has a corresponding part separated with hyphens. It's complicated but possible: https://regex101.com/r/3R1TQn/1 – Casimir et Hippolyte Mar 21 '17 at 12:38
  • 1
    You can also see these two posts that uses the same trick: http://stackoverflow.com/questions/23001137/capturing-quantifiers-and-quantifier-arithmetic and http://stackoverflow.com/questions/17039670/vertical-regex-matching-in-an-ascii-image – Casimir et Hippolyte Mar 21 '17 at 12:45

0 Answers0