lookbehind

Regexp for selecting spaces between digits and decimal char

I want to remove spaces from strings where the space is preceeded by a digit or a "." and acceded by a digit or ".". I have strings like: "50 .10", "50 . 10", "50. 10" and I want them all to become "50.10" but with an unknown number of digits on either side. I'm trying with lookahead/lookbehind assertions like this: $row = str_replace("...

Does lookaround affect which languages can be matched by regular expressions?

There are some features in modern regex engines which allow you to match languages that couldn't be matched without that feature. For example the following regex using back references matches the language of all strings that consist of a word that repeats itself: (.+)\1. This language is not regular and can't be matched by a regex, which...

How does the regular expression ‘(?<=#)[^#]+(?=#)’ work?

I have the following regex in a C# program, and have difficulties understanding it: (?<=#)[^#]+(?=#) I'll break it down to what I think I understood: (?<=#) a group, matching a hash. what's `?<=`? [^#]+ one or more non-hashes (used to achieve non-greediness) (?=#) another group, matching a hash. what's the `?=`? So the p...

Lazy Regex Match in .NET. What's wrong here?

Hi! In the following example I would like to retrieve the text between pMAINp and the first pMDSp. The regex has a look-behind and a look-ahead: string contents = "pMAINp MAP B FlightTest Load pMDSp ZutiCarrier pWingp some pMDSp more pWingp end"; string blockMainRegex = @"(?<=pMAINp)[\s\w+]+(?=(pMDS)?)"; The result I was hoping for w...

Why doesn't finite repetition in lookbehind work in some flavors?p

I want to parse the 2 digits in the middle from a date in dd/mm/yy format but also allowing single digits for day and month. This is what I came up with: (?<=^[\d]{1,2}\/)[\d]{1,2} I want a 1 or 2 digit number [\d]{1,2} with a 1 or 2 digit number and slash ^[\d]{1,2}\/ before it. This doesn't work on many combinations i have tested ...

Negative look-around

the following regexp is wrong - can someone please help to find all :-) that do not have "please ignore me " in front? I have not previously needed such an regexp. The word boundaries might confuse things. Thanks <script type="text/javascript"> function regexTest(string, assert) { document.write('<hr>') document.write(string) docu...

js regex escaping quotes

I want to escape all quotes that comes only after the text H1: For instance, : H1: "text here" should become: H1: &quot;text here&quot; This would be easy with lookbehind, but that's not in JS. something I tried: .replace(/H1:(.*)(")(.*)/ig, "H1:$1&quot;$2") Also it should work on other similar text like: H1: ""text here"" H1...

Ruby 1.9 Regex Lookbehind Assertion & Anchors

Ruby 1.9 regex supports lookbehind assertion but I seem to have difficulty when passing anchors in the pattern. When anchors are passed in the lookahead assertion it runs just fine. "well substring! "[/(?<=^|\A|\s|\b)substring!(?=$|\Z|\s|\b)/] #=> RegexpError: invalid pattern in look-behind: /(?<=^|\A|\s|\b)substring(?=$|\Z|\s|\b)/ Do...

What's the technical reason for "lookbehind assertion MUST be fixed length" in regex?

For example,the regex below will cause failure reporting lookbehind assertion is not fixed length: #(?<!(?:(?:src)|(?:href))=["\']?)((?:https?|ftp)://[^\s\'"<>()]+)#S Such kind of restriction doesn't exist for lookahead. ...

Regex to match tag contents while simultaneously omitting leading and trailing whitespace

I am trying to write a regex that matches entire contents of a tag, minus any leading or trailing whitespace. Here is a boiled-down example of the input: <tag> text </tag> I want only the following to be matched (note how the whitespace before and after the match has been trimmed): "text" I am currently trying to use...

How can I use lookbehind in a C# Regex in order to skip matches of repeated prefix patterns?

How can I use lookbehind in a C# Regex in order to skip matches of repeated prefix patterns? Example - I'm trying to have the expression match all the b characters following any number of a characters: Regex expression = new Regex("(?<=a).*"); foreach (Match result in expression.Matches("aaabbbb")) MessageBox.Show(result.Value); r...

Rexeg - Combining positive and negative lookbehind

I am doing some replaces in some huge SSIS packages to reflect changes in table- and column names. Some of the tabels have columnnames witch are identical to the tablenames and I need to match the columnname without matching the tablename. So what i need is a way to match MyName in [MyName] but not in [dbo].[MyName] (?<=\[)(MyName)(?=...