Regular Express - Pattern matching
How to include everything after /blog but shouldn't include words like wp-content and wp-includes?
Currently showing all using regex:
I tried this but no luck:
example.com/blog/content (should include) example.com/blog/page/2 (should include) example.com/blog/wp-content/ (shouldn't include) example.com/blog/wp-includes/ (shouldn't include)
Your first regex
Means a string, starting with /blog that has zero or more forward slashes after that. I'm guessing you meant just
As for how to exclude those two words:
The idea is to advance one character at a time (.), checking that wp-content or wp-includes doesn't follow after that using negative lookahead ((?!)) til the end of the string ($).
If you want to ensure the slash after blog is there without repeating the regex, you can put the negative lookahead first and then start matching characters:
This first ensures that there is no wp-content or wp-includes after any amout of characters (.*) and then continues matching.
you can use negative lookahead like this:
if the semantics of the match is "inside a url", then you most likely only want to match non-whitespace characters:
and if there are more than the 2 "wp-" examples:
..not using ^ because your examples do not match at the beginning of the string