negative-lookbehind

How do I match part of a string only if it is not preceded by certain characters?

I've created the following regex pattern in an attempt to match a string 6 characters in length ending in either "PRI" or "SEC", unless the string = "SIGSEC". For example, I want to match ABCPRI, XYZPRI, ABCSEC and XYZSEC, but not SIGSEC. (\w{3}PRI$|[^SIG].*SEC$) It is very close and sort of works (if I pass in "SINSEC", it returns a ...

A regex problem I can't figure out (negative lookbehind)

how do i do this with regex? i want to match this string: -myString but i don't want to match the -myString in this string: --myString myString is of course anything. is it even possible? EDIT: here's a little more info with what i got so far since i've posted a question: string to match: some random stuff here -string1, --string2...

Javascript: negative lookbehind equivalent?

Is there a way to achieve the equivalent of a negative lookbehind in javascript regular expressions? I need to match a string that does not start with a specific set of characters. It seems I am unable to find a regex that does this without failing if the matched part is found at the beginning of the string. Negative lookbehinds seem ...

How can regex ignore escaped-quotes when matching strings?

Hi, I'm trying to write a regex that will match everything BUT an apostrophe that has not been escaped. Consider the following: <?php $s = 'Hi everyone, we\'re ready now.'; ?> My goal is to write a regular expression that will essentially match the string portion of that. I'm thinking of something such as /.*'([^']).*/ in order t...

Help with PHP Regular Expressions using a Negative Look Behind

Hello, I'm trying to write a simple function to close missing HTML tags using PHP preg_replace. I thought it would be relatively straight-forward, but for some reason it hasn't been. What I'm basically trying to do is close a missing tag in the following row: <tr> <th class="ProfileIndent0"> <p>Global pharmaceuticals</p> <td>197...

Javascript does not support positive lookbehind

I have the following regular expression in .Net (?<=Visitors.{0,100}?"value">)[0-9,]+(?=) and the following text <div class="text">Visitors</div> <div class="value">14,000,000</div> <div class="text">VisitorsFromItaly</div> <div class="value">15,200</div> I specify in the regex either "Visitors" or "VisitorsFromItaly" and I get the...

negative lookbefore for a blackslash in ruby 1.9

I want to match every '[' or ']' that's not preceded by a backslash in ruby 1.9 I tried: /?<!\134[\[\]]/ and /?<!\\\\[\[\]]/ but I get a 'target of repeat operator not specified' ...

What's the easiest way to get an equivalent to GNU grep that supports negative lookbehinds?

I'm trying to grep through a bunch of files in nested subdirectories to look for regular expression matches; my regex requires negative lookbehind. Perl has negative lookbehind, but as far as I can tell GNU grep doesn't support negative lookbehinds. What's the easiest way to get an equivalent to GNU grep that supports negative lookbehi...

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 look-behind in hgignore file

I'm looking for a way to modify my .hgignore file to ignore all "Properties/AssemblyInfo.cs" files except those in either the "Test/" or the "Tests/" subfolders. I tried using the negative look-behind expression (?<!Test)/Properties/AssemblyInfo\.cs$, but I didn't find a way to "un-ignore" in both folders "Test/" and "Tests/". ...

[Regexp] Stop matching when meeting a sequence of chars: fixing a lookbehind

Hello everyone! I have the following regexp: (?P<question>.+(?<!\[\[)) It is designed to match hello world! in the string hello world! [[A string typically used in programming examples]] Yet I just matches the whole string, and I can't figure out why. I've tried all flavors of lookaround, but it just won't work... Anyone knows how ...

strange behavior in vim with negative look-behind

So, I am doing this search in vim: /\(\(unum\)\|\(player\)=\)\@<!\"1\" and as expected it does not match lines that have: player="1" but matches lines that have: unum="1" what am i doing wrong? isn't the atom to be negated all of this: \(\(unum\)\|\(player\)=\) naturally just doing: /\(\(unum\)\|\(player\)=\) matches unum= or...

Java RegEx API "Look-behind group does not have an obvious maximum length near index ..."

Hello, I'm on to some SQL where clause parsing and designed a working RegEx to find a column outside string literals using "Rad Software Regular Expression Desginer" which is using the .NET API. To make sure the designed RegEx works with Java too, I tested it by using the API of course (1.5 and 1.6). But guess what, it won't work. I got...

Need variable width negative lookbehind replacement

I have looked at many questions here (and many more websites) and some provided hints but none gave me a definitive answer. I know regular expressions but I am far from being a guru. This particular question deals with regex in PHP. I need to locate words in a text that are not surrounded by a hyperlink of a given class. For example, I ...

negative lookbehind and greedy quantifiers in php

I'm using a regex to find any URLs and link them accordingly. However, I do not want to linkify any URLs that are already linked so I'm using lookbehind to see if the URL has an href before it. This fails though because variable length quantifiers aren't allowed in lookahead and lookbehind for PHP. Here's the regex for the match: /\b(?...

Making Regular Expression more efficient

I'm attempting to determine the end of an English sentence (only approximately), by looking for "!", "?" or ".", but in the case of "." only when not preceeded by common abbreviations such as Mr. or Dr. Is there any way to make the following Regular Expression even marginally more efficient? Perhaps by sorting the negative lookbehinds ...