-1

I have the following sample urls

/alfa/wp-includes/js/jquery/jquery.js /beta/wp-content/plugins/app/js/media.js?parameter=value /beta/wp-admin/network /beta/wp-content/themes/journal/data.php

I'm using the following regex to match all paths, excluding paramethers

^/(alfa|beta)((/wp-(content|admin|includes))([^?\s]*)).*

This works well, but how to change the regex to exclude any paths which include a .php ? So it needs to return first 3 paths but not the last.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Joe S
  • 13
  • 2

2 Answers2

0

The solution i looked for is the following, thanks @chris85

.*\.php(*SKIP)(*FAIL)|^/(alfa|beta)((/wp-(content|admin|includes))([^?\s]*)).*
Joe S
  • 13
  • 2
0

You can use the PCRE verbs skip and fail to skip over matches of expressions. You can read more about them here, http://www.rexegg.com/backtracking-control-verbs.html#skipfail. For your current example you can use:

.*\.php$(*SKIP)(*FAIL)|^/(alfa|beta)((/wp-(content|admin|includes))([^?\s]*)).*

which would skip files that end in .php.

Demo: https://regex101.com/r/YH3n0x/1/

The .*\.php$ looks for anything until a .php at the end of the string/line.

chris85
  • 23,846
  • 7
  • 34
  • 51