negative-lookahead

RegEx matching with no single letter delimiter

Medicare Eligibility EDI Example Responses is what I'm trying to match. I have a string that looks like this: LN:SMITHbbbbbbbbFN:SAMANTHAbbBD:19400515PD:1BN:123456PN:9876543210GP:ABCDEFGHIJKLMNOID:123456789012345bbbbbPC:123PH:8005551212CD:123456PB:123ED:20060101TD:2070101LC:NFI:12345678FE:20070101FT:20080101 I need a set of matches th...

Need a regex to match a variable length string of numbers that can't be all zeros

I need to validate an input on a form. I'm expecting the input to be a number between 1 to 19 digits. The input can also start with zeros. However, I want to validate that they are not all zeros. I've got a regex that will ensure that the input is numeric and between 1 and 19 numbers. ^\d[1,19]$ But I can't figure out how to include a...

Replace Local Links, Keep External Links

Hi guys, I have an API call that essentially returns the HTML of a hosted wiki application page. I'm then doing some substr, str_replace and preg_replace kung-fu to format it as per my sites style guides. I do one set of calls to format my left nav (changing a link to pageX to my wikiParse?page=pageX type of thing). I can safely do thi...

String negation using regular expressions

Is it possible to do string negation in regular expressions? I need to match all strings that do not contain the string "..". I know you can use ^[^\.]*$ to match all strings that do not contain "." but I need to match more than one character. I know I could simply match a string containing ".." and then negate the return value of the...

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...

Regex: what does (?! ...) mean?

The following regex finds text between substrings FTW and ODP. /FTW(((?!FTW|ODP).)+)ODP+/ What does the (?!...) do? ...

Java Regex not working - why?

match.matches() returns false. This is odd, because if I take this regex and test String to rubular.com, is shows two matches. What am I doing wrong? Pattern regex = Pattern.compile("FTW(((?!ODP).)+)ODP"); Matcher match = regex.matcher("ZZZMMMJJJOOFTWZMJZMJODPZZZMMMJJJOOOFTWMZJOMZJOMZJOODPZZZMMMJJJOO"); if (match.matches()) { Syst...

Alternative regular expression to do this "\.(asmx(?!/js)|aspx|htm)"

Is there a way to rewrite this regex expression such that it does not include a lookahead for "/js"? Is this even something that I should worry about in terms of performance? It is being used to filter HTTP requests. \.(asmx(?!/js)|aspx|htm) Edit: To be clear: I'd like to specifically prevent ".asmx/js" but allow all other .asmx re...

Regular expression negative lookahead

In my home directory I have a folder drupal-6.14 that contains the Drupal platform. From this directory I use the following command: find drupal-6.14 -type f -iname '*' | grep -P 'drupal-6.14/(?!sites(?!/all|/default)).*' | xargs tar -czf drupal-6.14.tar.gz What this command does is gzips the folder drupal-6.14, excluding all subfold...

RegExp: want to find all links that do not end in ".html"

Hi, I'm a relative novice to regular expressions (although I've used them many times successfully). I want to find all links in a document that do not end in ".html" The regular expression I came up with is: href=\"([^"]*)(?<!html)\" In Notepad++, my editor, href=\"([^"]*)\" finds all the links (both those that end in "html" and thos...

Regex negative lookahead

I need to modify this regex href=\"(.*)\" which matches this... href="./pothole_locator_map.aspx?lang=en-gb&lat=53.153977&lng=-3.533306" To NOT match this... href="./pothole_locator_map.aspx?lang=en-gb&lat=53.153977&lng=-3.533306&returnurl=AbandonedVehicles.aspx" Tried this, but with no luck href=\"(.*)\"(?!&returnurl=Abandoned...

negative look ahead to exclude html tags

I'm trying to come up with a validation expression to prevent users from entering html or javascript tags into a comment box on a web page. The following works fine for a single line of text: ^(?!.*(<|>)).*$ ..but it won't allow any newline characters because of the dot(.). If I go with something like this: ^(?!.*(<|>))(.|\s)*$ i...

RegEx: h1 followed by h2 without p in between

Hey everyone, I need a regular expression to find out whether or not a h1 tag is followed by a h2 tag, without any paragraph elements in between. I tried to use a negative lookahead but it doesn't work: <h1(.+?)</h1>(\s|(?!<p))*<h2(.+?)</h2> ...

C# regex: negative lookahead fails with the single line option

I am trying to figure out why a regex with negative look ahead fails when the "single line" option is turned on. Example (simplified): <source>Test 1</source> <source>Test 2</source> <target>Result 2</target> <source>Test 3</source> This: <source>(?!.*<source>)(.*?)</source>(?!\s*<target) will fail if the single line option is on...

How to make negative lookahead work with end of line text

Hi, I have a regex like the following: .{0,1000}(?!(xa7|para(graf))$) using Java. I was expecting that it would cause the following text to fail: blaparagraf because paragraf is found at the end ...

Complex(?) regex: Is expression, but not another

(If you can make a better title, please do) Hi, I need to make sure a string matches the following regex: ^[0-9a-zA-Z]{1}[0-9a-zA-Z\.\-_]*$ (Starts with a letter or number, then any number of letters, numbers, dots, dashes or underscores) But given that, I need to make sure it doesn't match a Guid, my Guid matching reg-ex looks like...

Specific Perl Regular Expression Needed

Hi all. Have a perl script that needs to process all files of a certain type from a given directory. The files should be those that end in .jup, and SHOULDN'T contain the word 'TEMP_' in the filename. I.E. It should allow corrected.jup, but not TEMP_corrected.jup. Have tried a look-ahead, but obviously have the pattern incorrect: /(...

Perl regex using negative look? can't seem to figure out how to do this properly

I'm trying to get this to work with perl's regex but can't seem to figure it out.. I want to grab any url that has ".website." in it, except ones that are like this (with "en" preceding ".website." $linkhtml = 'http://en.search.website.com/?q=beach&amp;' ; This is an example of a url that I would want to be returned by the regex, ...

using regex to skip ahead all characters until a specific sequence of letters is found using negative lookahead

I'm alright with basic regular expressions, but I get a bit lost around pos/neg look aheads/behinds. I'm trying to pull the id # from this: [keyword stuff=otherstuff id=123 morestuff=stuff] There could be unlimited amounts of "stuff" before or after. I've been using The Regex Coach to help debug what I've tried, but I'm not moving for...

Javascript RegExp replace with negative lookahead

Hi, I am trying to replace some value in the query string of the current page using JS. Eg: from category=Old Value to category=New Value. To code looks like this: var sNewValue = 'New Value'; sQueryString = sQueryString.replace(/category=[^&]+&?/, 'category=' + sNewValue); It works fine except for values that have ampersands. Luckil...