A lookbehind is a part of the regular expression standard.
Questions tagged [lookbehind]
356 questions
5
votes
1 answer
Quantifier range not working in lookbehind
Okay so I'm working on a project where I need a regex that can match a * followed by 1-4 spaces or tabs and then followed by a row of text. Right now I'm using .* after the lookbehind for testing purposes. However I can get it to match explicitly 1,…
Hultner
- 3,264
- 4
- 31
- 41
5
votes
1 answer
RegEx don't match if starts with character?
I have this regex:
/(((\w+)|(\.\w+)|(\#\w+)|\*)(\[(.+(=".+"|\*".+"|\^".+"|))\])?(::|:)?)+(?=[ \S]*\{)/gm
Which I am trying to use to match CSS selectors. Consider this pseudo-code CSS input:
.main {
property: value;
}
.one, .two a[href$=".com"]…
topherlicious
- 153
- 3
- 10
5
votes
2 answers
Parsing text between quotes with .NET regular expressions
I have the following input text:
@"This is some text @foo=bar @name=""John \""The Anonymous One\"" Doe"" @age=38"
I would like to parse the values with the @name=value syntax as name/value pairs. Parsing the previous string should result in the…
Anthony Grescavage
- 53
- 5
5
votes
2 answers
grep regex lookahead or start of string (or lookbehind or end of string)
I want to match a string which may contain a type of character before the match, or the match may begin at the beginning of the string (same for end of string).
For a minimal example, consider the text n.b., which I'd like to match either at the…
cosmicexplorer
- 491
- 6
- 14
5
votes
1 answer
5
votes
3 answers
RegEx Advanced : Positive lookbehind
This is my test-string:
I want to get each of the JSON formed Elements inbetween the rel attribute.
It's working…
mpneuried
- 51
- 2
5
votes
2 answers
Positive lookbehind vs non-capturing group: different behaviuor
I use python regular expressions (re module) in my code and noticed different behaviour in theese cases:
re.findall(r'\s*(?:[a-z]\))?[^.)]+', 'a) xyz. b) abc.') # non-capturing group
# results in ['a) xyz', ' b)…
aplavin
- 2,129
- 3
- 30
- 50
5
votes
1 answer
.NET Regex Lookbehind Not Greedy
How to get the lookbehind to be greedy?
In this case I want the lookbehind to consume the : if is is present.
m = Regex.Match("From: John", @"(?i)(?<=from:)....");
// returns ' Jon' what I expect not a problem just an example
m = Regex.Match("From:…
paparazzo
- 42,665
- 20
- 93
- 158
4
votes
4 answers
Invalid regular expression error
I'm trying to retrieve the category part this string "property_id=516&category=featured-properties", so the result should be "featured-properties", and I came up with a regular expression and tested it on this website http://gskinner.com/RegExr/,…
KarimMesallam
- 290
- 7
- 19
4
votes
3 answers
Regular Expression - Match all but first letter in each word in sentence
I've almost got the answer here, but I'm missing something and I hope someone here can help me out.
I need a regular expression that will match all but the first letter in each word in a sentence. Then I need to replace the matched letters with the…
mahdaeng
- 741
- 4
- 14
- 25
4
votes
1 answer
Regex with lookbehind not working using re.match
The following python code:
import re
line="http://google.com"
procLine = re.match(r'(?<=http).*', line)
if procLine.group() == "":
print(line + ": did not match regex")
else:
print(procLine.group())
does not match successfully, and outputs…
Lost Crotchet
- 860
- 8
- 14
4
votes
1 answer
Inserting bold text with knitr and LaTeX for terms that have already been indexed
My PDF produced by knitr and LaTeX using RStudio has more than 200 indexed terms. I realized too late that it would be good to bold those indexed terms so that I can spot them in the PDF. It seems plausible that there is a way to automate that…
lawyeR
- 6,804
- 3
- 23
- 56
4
votes
1 answer
Regular expressions positive lookbehind + negative lookahead
Given a string "A B C a b B" I want to match words that are repeated (regardless of case). Expected result would be matching "a" and "b" (last occurrences of A and B) OR "A" and "B" (first occurrences)
EDIT: I want to match only the first or the…
Eugene Krapivin
- 1,340
- 2
- 13
- 28
4
votes
4 answers
How to use '\' in Python lookbehind assertion regex (?<=\\) to match C++-like quoted strings
How can I match r'\a' in Python using lookbehind assertion?
Actually, I need to match C++ strings like "a \" b" and
"str begin \
end"
I tried:
>>> res = re.compile('(?<=\)a')
Traceback (most recent call last):
File "", line 1, in…
luart
- 1,135
- 1
- 13
- 22
4
votes
2 answers
R: workaround for variable-width lookbehind
Given this vector:
ba <- c('baa','aba','abba','abbba','aaba','aabba')'
I want to change the final a of each word to i except baa and aba.
I wrote the following line ...
gsub('(?<=a[ab]b{1,2})a','i',ba,perl=T)
but was told: PCRE pattern…
dasf
- 995
- 7
- 12