HelpNeeder
HelpNeeder

Reputation: 6480

Do not match string when it contains a word

I need to skip a query string when the first word is 'page'.

Currently I am using a string separated by slashes and use them as parameters of the query string like so:

^(.*)$      // string with 1 parameter
^(.*)/(.*)$ // string with 2 parameters

How would I skip matching entirely if the string contains the word 'page' before first or no slash?

This is what I'm trying to do but it still returns some values but skips the word.

((?![page]).*)

http://regex101.com/r/dA3jE7/1

Example:

word // match
some/word // match
word/somepage // match
page // do not match
page/word // do not match

Upvotes: 0

Views: 98

Answers (2)

Kannan Mohan
Kannan Mohan

Reputation: 1840

An other way of doing it using negative look ahead.

^(?!page)(\w+\/?)+$

Output

Upvotes: 1

hwnd
hwnd

Reputation: 70722

You want to remove the character class wrapped around your whole word.

^(?!page).*$

Upvotes: 2

Related Questions