lookbehind

Ruby Regex match unless escaped with \

Using Ruby I'm trying to split the following text with a Regex ~foo\~\=bar =cheese~monkey Where ~ or = denotes the beginning of match unless it is escaped with \ So it should match ~foo\~\=bar then =cheese then ~monkey I thought the following would work, but it doesn't. ([~=]([^~=]|\\=|\\~)+)(.*) What is a better regex ex...

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

Regex: How to match the first word after an expression

For example, in this text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eu tellus vel nunc pretium lacinia. Proin sed lorem. Cras sed ipsum. Nunc a libero quis risus sollicitudin imperdiet. I want to match the word after 'ipsum'. ...

RegExp in ActionScript 3: How to exclude a complex prefix?

Hi, AS3 RegExp engine (and ECMAScript based JavaScript) do not support complex "lookbehind" expressions. (lookahead expressions are fully supported.) For example: (?<=<body>)(.*?)(?=<\/body>) will work but; (?<=<body\b[^>]*>)(.*?)(?=<\/body>) will not work in AS3. What I need is to match a complex prefix but exclude it in the ...

Extract a portion of text using RegEx

Hi, I would like to extract portion of a text using a regular expression. So for example, I have an address and want to return just the number and streets and exclude the rest: 2222 Main at King Edward Vancouver BC CA But the addresses varies in format most of the time. I tried using Lookbehind Regex and came out with this expression...

Help with negative lookbehind in regular expressions

I am working on a ASP.NET response filter that rewrites URL's to point to a different domain in specific situations. Because ASP.NET chunks the response writes, my filter gets called several times before the page is fully streamed. This means that I need to be careful that each call to Regex.Replace doesn't double replace a url (You end...

How to non-greedy multiple lookbehind matches

Source: <prefix><content1><suffix1><prefix><content2><suffix2> Engine: PCRE RegEx1: (?<=<prefix>)(.*)(?=<suffix1>) RegEx2: (?<=<prefix>)(.*)(?=<suffix2>) Result1: <content1> Result2: <content1><suffix1><prefix><content2> The desired result for RegEx2 is just <content2> but it is obviously greedy. How do I make RegEx2 ...

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

How to use lookbehind or lookahead and replace the matched string?

Hi, I am stuck at one more RegEx. Sample input : project description I want to write RegEx. that if word "description" is found and its preceded by word "project" then prepend "project description" with "<project>". expected output : <project>project description I wrote following Regex, n replacement string but its not working :...

Replace all "\" characters which are *not* inside "<code>" tags

First things first: Neither this, this, this nor this answered my question. So I'll open a new one. Please read Okay okay. I know that regexes are not the way to parse general HTML. Please take note that the created documents are written using a limited, controlled HTML subset. And people writing the docs know what they're doing. They ...

Regular expression lookbehind problem

Hi folks, I use (?<!value=\")##(.*)## to match string like ##MyString## that's not in the form of: <input type="text" value="##MyString##"> This works for the above form, but not for this: (It still matches, should not match) <input type="text" value="Here is my ##MyString## coming.."> I tried: (?<!value=\").*##(.*)## w...

Problem with look behind assertion and optional substring

I'm trying to write some regex that will parse information from alerts generated by Hyperic HQ. The alerts come in as emails with a subject line like: "[HQ] !!! - Alert: My Demo Website Alert Resource: demo.myserver.net Apache Web Server State: fixed" To cut a very long story short, I need to be able to consistently grab the "Apache W...

Can you salvage my negative lookbehind example for commifying numbers?

In the "Advanced Regular Expresssion" chapter in Mastering Perl, I have a broken example for which I can't figure out a nice fix. The example is perhaps trying to be too clever for its own good, but maybe someone can fix it for me. There could be a free copy of the book in it for working fixes. :) In the section talking about lookaround...

Naming convetion of regex,lookahead and lookbehind

Why is it counter intuitive? /(?<!\d)\d{8}(?!\d)/,here (?<!\d) comes first,but called lookbehind,(?!\d) next,but called lookahead.All are counter intuitive. What's the reason to name it this way? ...

RegEx Advanced : Positive lookbehind

This is my test-string: <img rel="{objectid:498,newobject:1,fileid:338}" width="80" height="60" align="left" src="../../../../files/jpg1/Desert1.jpg" alt="" /> I want to get each of the JSON formed Elements inbetween the rel attribute. It's working for the first element (objectid). Here is my ReqEx, which works fine: (?<=(rel="\{obj...

Java RegExp ViewState

I am porting some functionality from a C++ application to java. This involves reading non-modifiable data files that contain regular expressions. A lot of the data files contain regular expressions that look similar to the following: (?<=id="VIEWSTATE".*?value=").*?(?=") These regular expressions produce the following error: "Look-...

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

PHP - REGEX - use string for pattern but exclude it from being removed!

Hi All guys! i'm pretty new on regex, i have learned something by the way, but is still pour knowledge! so i want ask you for clarification on how it work! assuming i have the following strings, as you can see they can be formatted little different way one from another but they are very similar! DTSTART;TZID="America/Chicago":2003081...

Backreferences in lookbehind

Can you use backreferences in a lookbehind? Let's say I want to split wherever behind me a character is repeated twice. String REGEX1 = "(?<=(.)\\1)"; // DOESN'T WORK! String REGEX2 = "(?<=(?=(.)\\1)..)"; // WORKS! System.out.println(java.util.Arrays.toString( "Bazooka killed the poor aardvark (yummy!)" .sp...

Remove leading whitespaces using variable length lookbehind in RegExp

Hello, I'm wondering if variable length lookbehind assertions are supported in JavaScript's RegExp engine? For example, I'm trying to match the string "variable length" in the string "[a lot of whitespaces and/or tabs]variable length lookbehind", and I have something like this but it does not go well in various RegExp testers: ^(?<=[ ...