Regex that does not contain a substring after some point

regex does not contain character
regex does not contain string
regex does not contain multiple words
javascript regex
lines not containing regex
regex negative lookahead
regular expression match word in string
regex line not contain

I want a regex that doesn't match a string if contains the word page, and match if it's not contain.

^https?.+/(event|news)/.+(?!page).+$ this is the regex I'm currently using, so I want it to not match with, e.g. https://www.foosite.com/news/foopath/page/10, but it does. Where did I made a mistake?

The double .+ expressions should imply that there should be some string around the page string, and (?!page) should imply there must not be a string like page between them. What's wrong with this expression? Thanks, and sorry for poor grammar.


Your problem is that .+(?!page).+ will match foopath/page/10 because the first .+ match can end at the 1 in 10, and the second can match from there until $. Instead, just assert there is no combination of characters plus the word page after (event|news)/:

^https?.+/(event|news)/(?!.*page)

Demo on regex101

If you want more than just a match/nomatch decision, you can capture the entire matching string with this regex:

^https?.+/(event|news)/(?!.*page).*$

Demo on regex101

Creating a Regex expression with a “not” condition for a specific , I have a use case where I am searching for a particular sub string in a string and if that particular string contains another particular sub string I  The regex example from @armingrudd was helpful to get my mind going in that direction, but because the data values aren’t always in the same order, I can’t be sure what values are in what columns after splitting, or if a value is missing completely, then some rows will have a different number of columns.


You might be looking for

^https?.+/(event|news)/(?:(?!page).)+$

See a demo on regex101.com.

Elements of Computation Theory, (e) w does not contain aab as a substring. For finite representation of languages, we have defined the regular expressions, which are again strings of symbols Perhaps, after some time you will be able to solve them with the help of your  ([^1] | (1[^1])*)* or simply ([^1] | 1[^1])* I arrived at this regular expression by first building a DFA for L= all strings that contain 11 as a substring. Then I built an DFA for the complement of L.


Matching is usually way easier in regex than excluding.

I would rather match your excluded words and invert the logic on the if-clause.

if(!re.match(...

Algorithms on Strings, Trees, and Sequences: Computer Science and , Why not? Can you fix it and make it run in O(n + m) time? Suppose we have q > 1 G(R) from a regular expression R. The construction should have the property that if PROSITE patterns often specify the number of times that a substring can​  Suppose you want to validate so that a phrase starts with "string" and ends with "bee", but does not contain "like". You could use this regular expression (which uses a negative lookahead): (?!.*like)^sting.*bee$ The negative look ahead will ensure that the expression will not match if the phrase contains "like".


Regex matching line not containing the string, Regular expressions are a way to describe patterns in string data. Some characters, such as question marks and plus signs, have special meanings in Something with a star after it never prevents a pattern from matching—it'll just match When a group does not end up being matched at all (for example, when followed  The regex above will match any string, or line without a line break, not containing the (sub)string ‘hede’. As mentioned, this is not something regex is “good” at (or should do), but still, it is possible. And if you need to match line break chars as well, use the DOT-ALL modifier (the trailing s in the following pattern):


Regular Expressions :: Eloquent JavaScript, Regular expression examples showing how you can match an entire line of text in a file, taking into account certain conditions as to what the line must or must not contain. the parts of the line before and after the match of our original regular expression John, we Be sure to turn off the option for the dot to match newlines. Regular expression is used to : (1) test a string whether it matches a pattern, such as a email address. (2) to find a substring which matches certain pattern, from a whole text. (3) to do complex replacement in a text. It is very simple to study regular expression syntax, and the few abstract concepts can be understood easily too.


Regex Examples: Matching Whole Lines of Text That Satisfy Certain , If pattern does not contain percent signs or underscores, then the pattern only In some obscure cases it may be necessary to use the underlying operator names A string is said to match a regular expression if it is a member of the regular re ), negative lookahead matches at any point where no substring matching re  Match string not containing string Given a list of strings (words or other characters), only return the strings that do not match.