regex-negation

Regex to match against something that is not a specific substring

I am looking for a regex that will match a string that starts with one substring and does not end with a certain substring. Example: // Updated to be correct, thanks @Apocalisp ^foo.*(?<!bar)$ Should match anything that starts with "foo" and doesn't end with "bar". I know about the [^...] syntax, but I can't find anything that will ...

RegEx to tell if a string does not contain a specific character

Easy question this time. I'm trying to test whether or not a string does not contain a character using regular expressions. I thought the expression was of the form "[^x]" where x is the character that you don't want to appear, but that doesn't seem to be working. For example, Regex.IsMatch("103","[^0]") and Regex.IsMatch("103&","...

Regular expression to match string not containing a word?

I know it is possible to match for the word and using tools options reverse the match. (eg. by grep -v) However I want to know if it is possible using regular expressions to match lines which does not contain a specific word, say hede? Input: Hoho Hihi Haha hede # grep "Regex for do not contain hede" Input Output: Hoho Hihi Haha ...

Regex: Matching by exclusion, without look-ahead - is it possible?

In some regex flavors, [negative] zero-width assertions (look-ahead/look-behind) are not supported. This makes it extremely difficult (impossible?) to state an exclusion. For example "every line that does not have "foo" on it", like this: ^((?!foo).)*$ Can the same thing be achieved without using look-around at all (complexity and p...

How would you use a regular expression to ignore strings that contain a specific substring?

How would I go about using a negative lookbehind(or any other method) regular expression to ignore strings that contains a specific substring? I've read two previous stackoverflow questions: java-regexp-for-file-filtering regex-to-match-against-something-that-is-not-a-specific-substring They are nearly what I want... my problem is the ...

Regular expression that doesn't contain certain string

I have something like this aabbabcaabda for selecting minimal group wrapped by a I have this /a([^a]*)a/ which works just fine But i have problem with groups wrapped by aa, where I'd need something like /aa([^aa]*)aa/ which doesn't work, and I can't use the first one like /aa([^a]*)aa/, because it would end on first occurence of ...

Remove punctuation marks except apostrophe Regex

Hello. preg_replace ("/(\p{P})/", ' ', $str) removes apostrophes, and it should not. Please help ...

regexp to match string1 unless preceded by string2

Using Ruby, how can I use a single regex to match all occurrences of 'y' in "xy y ay xy +y" that are NOT preceded by x (y, ay, +y)? /[^x]y/ matches the preceding character too, so I need an alternative... ...

Regular expression negative replace?

I need to get "yomomedia.com" if the HTTP_HOST is [ANY].yomomedia.com except in the cases where it is "dev.yomomedia.com" else it should return dev.yomomedia.com echo preg_replace("/^([EVERYTHING-OTHER-THAN-DEV])\./Ui","",$_SERVER['SERVER_NAME']) Just tried the following with no success: echo preg_replace("/^(?!dev)\./Ui",'','www.yom...

Writing a Regular Expression for not including something.

How can I write a Regular Expression to match, a string which does not contain the underscore "_". ...

How can I combine a positive and negative condition in a regex?

I fairly new to regular expressions and need some help. I need to filter some lines using regex in Perl. I am going to pass the regex to another function so it needs to be done in a single line. I want to select only lines that contain "too long"and that don't begin with "SKIPPING" Here are my test strings: SKIPPING this bond sinc...

C# regex to match a string that doesn't contain a certain string?

This should be an easy one for the Regex experts out there... :) I want to match any string that does not contain the string "DontMatchThis". What's the regex? ...

Match a string that does not contain a certain character sequence

I'm trying to use regular expressions to match a string that does not contain the sequence of characters of a less than symbol (<) followed by a non space. Here are some examples Valid - "A new description." Valid - "A < new description." Invalid - "A <new description." I can't seem to find the right expression to get a match. I'm usi...

Negating a set of words via java regex!

Hi folks, I would like to negate a set of words using java regex. Say, I want to negate cvs, svn, nvs, mvc. I wrote a regex which is ^[(svn|cvs|nvs|mvc)]. Some how that seems not to be working. Could you please help? Thanks. .\J ...

RegEx to exclude a specific string constant

Can regular expression be utilized to match any string except a specific string constant let us say "ABC" ? Is this possible to exclude just one specific string constant? Thanks your help in advance. ...

Regex challenge - find "foobar" in HTML document

I have a fairly long and complex HTML document, and I need to find all occurences of a given string, e.g. "foobar", unless it's between <a> and </a> anchor tags. The trouble is: it could be inside some text between the anchor tags, e.g. <a>this is a foobar test</a> and even in this case, I should not find the match. How can I do th...

Simple C# regex

I have a regex I need to match against a path like so: "C:\Documents and Settings\User\My Documents\ScanSnap\382893.pd~". I need a regex that matches all paths except those ending in '~' or '.dat'. The problem I am having is that I don't understand how to match and negate the exact string '.dat' and only at the end of the path. i.e. I...

Simple regex negation

Trying to match ONLY the first character in the sample below. Sample string: C/C++/Objective C/Objective-C/ObjectiveC/objectiveC My faulty regex: (?![O|o]bjective[ |-]?)C(?!\+\+) Doh. ...

White listing certain HTML tags in python?

Let's say allowed_bits = ['a', 'p'] re.compile(r'<(%s)[^>]*(/>|.*?</\1>)' % ('|'.join(allowed_bits))) matches: <a href="blah blah">blah</a> <p /> and not: <html>blah blah blah</html> What I want to do is turn it on its head, so that it matches <html>blah blah</html> <script type="text/javascript">blah blah</script> and not: ...

regex to not match if a specified string exists

i'm trying to do an apache rewrite where if the term "admin" is contained in the request_uri mydomain.com/admin/anything_else re-write the host to use a subdomain admin.mydomain.com/admin/anything_else. likewise, if i click a link while in the admin.mydomain.com and it is a url WITHOUT "admin" in it, then i would like to rewrite the ...