regex-negation

Why does this regex, using "not" & a backref, require a lazy match?

When using the not ^ operator in combination with a back reference, why do I need to use a lazy match? It seems like the not should break the match. For example: <?php preg_match('/(t)[^\1]*\1/', 'is this test ok', $matches); echo $matches[0]; ?> Will output this test, instead of this t, in spite of the fact that the middle t does no...

Regex negation - word parsing

I am trying to parse a phrase and exclude common words. For instance in the phrase "as the world turns", I want to exclude the common words "as" and "the" and return only "world" and "turns". (\w+(?!the|as)) Doesn't work. Feedback appreciated. ...

Regex match everything but ...

Hi, I would like to create a regular expression to match every word, whitespace, punctuation and special characters in a string except for specific keywords or phrases. Because I only can modify regex, not server code I have to use match instead of replace. I have something like this so far: (?!(quick|brown|fox|the lazy))\b\w+ but it i...

Excluding strings using regex

I was working on creating a regex which will include all patterns except 'time', 'hour', 'minute' so, worked this out: ^(?:(?!time).)*$ how do i add for the other 2 words also? I tried as follows but it is incorrect. ^(?:(?![time][hour][minute]).)*$ Is there a better way to do this? I am not adding the values which can be accepted...

How can I capture all nonempty sequences of letters other than cat, dog, fish using a regular expression?

Please explain why the expression makes sense if it is complicated. ...

Regular expression to match "wap" not preceeded by "html"

Hey, I'm using NGINX to segment mobile traffic between a mobile WAP/HTML site. Looks like the best way to do this is going to be to check the UA's preference for content by checking the HTTP Accept Header. A preference for WAP is indicated by the appearance of a 'wap' mimetype in the header before an 'html' or wildcard mimetype. So a ...

Excluding all characters NOT in list AND NOT in a list of phrases

I'm attempting to make a function in PHP that will evaluate a mathematical expression -- including functions such as sin, cos, etc. My approach is to delete all characters in the phrase that are not numbers, mathematical operators, or mathematical functions and then use that string in an eval(). The problem is that I don't know enough ...

Negating Alternation In Regular Expressions

I can use "Alternation" in a regular expression to match any occurance of "cat" or "dog" thusly: (cat|dog) Is it possible to NEGATE this alternation, and match anything that is NOT "cat" or "dog"? If so, how? For Example: Let's say I'm trying to match END OF SENTENCE in English, in an approximate way. To Wit: (\.)(\s+[A-Z][^.]|\s...

Help With Particular Regular Expression - Not Containing Some String

How do I say, in regular expressions: Any portion of a string beginning with a capital letter, containing at least one space character, not containing the string " _ " (space underscore space), and ending with the string "!!!" (without the quotes)? I am having trouble with the "not containing" part. Here is what I have so far: [A-Z]....

How do I turn any regex into an complement of itself without complex hand editing?

The following are pseudo examples, not real regex, but still an example of what I mean: .* (anything) -.* (NOT anything) [A-Z] (Any letter A to Z, caps only) -[A-Z] (NOT any letter A to Z, caps only) EDIT: Changed inverse into complement in the question. Here's where the change was made: "turn any regex into an complement of...

Reg Ex negation

I am using .Net. I want to match last name which has charecters other than a-z, A-Z, space and single quote and len of charecters should not be between 1-40 . The string that has to be matched is a XML look like this <FirstName>SomeName</FirstName><LastName>SomeLastName</LastName><Address1>Addre1</Address1> I wrote regualr expression b...

Reg Ex negation not working in XML string

I am trying to apply negation on regular expression in .Net. It does not work. When string has valid last name reg ex should not match. For invalid last name it should match. Valid name allows only charecters, spaces, single quote and length between 1-40. Somebody suggested to parse the XML, I don't want to do that. I know there is anoth...