1

/news/article-title.html

is not being caught by the regex:

^/news/[^(archives)].+.html

?

I'm trying to have articles that do NOT have "archives" in the filename, but start with "/news/"

Thanks!

2
  • [] defines one character from a character class. [^(archives)] translates to "one character that is not one of these: archives()". Commented Mar 11, 2011 at 16:39
  • so how do I say "not the entire string 'archives'" ? Commented Mar 11, 2011 at 18:17

2 Answers 2

6

You should use a negative lookahead. Character classes only work for a single character. Also, don't forget to escape the dot.

If "archives" cannot be at the beginning:

^/news/(?!archives).+\.html

If "archives" cannot anywhere:

^/news/((?!archives).)+\.html

More tips:

  • Disallow archives as a whole word: (?!archives\b).+ or (?!archives-).+
  • make sure \.html is at the end (it may appear more than once): \.html(?=$|[?&])
Sign up to request clarification or add additional context in comments.

1 Comment

Why be so specific about unspecified forms?
1

You can't use the not of a character block to not an entire string.

[^(archives)]

This is interpreted as a character that is not one of the following: (, a, r, c, h, i, v, e, s or ).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.