FAQ Database Discussion Community


Match a pattern preceded by a specific pattern without using a lookbehind

regex,eclipse,lookahead
Is there a way to match a B only if preceded by an A? The A can be at any position behind the B, with any amount of characters between. Examples: A_B (Matches `B`) C_B (No match) I've tried: (?=A)[^B]*B But it matches all the characters preceeding B as well....

How can I adjust my positive lookahead RegEx statement?

regex,string,lookahead
I have a really simple question about my positive lookahead, but I don't get it. My String looks like this: caused by: System.StringException: Invalid id: 3285673465734 And I am using this RegEx: caused by: (.+(?=:)): (.+)[\s]+ I want to have this groups: System.StringException Invalid id: 3285673465734 but the positive lookahead...

grep regex lookahead or start of string (or lookbehind or end of string)

regex,grep,lookahead,lookbehind
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 beginning of...

Capture a substring of a matched group

regex,lookahead,capturing-group
Scanario I have to grab a substring from a composed string. Match condition: string starts with 'section1:' captured string may be a blank separated or a dash separated list of alphanumerical values if the captured string ends with a specific suffix ('-xx'), exclude the suffix from the captured string. Examples...

grepl in R: matching impeded by intra-word dashes

regex,r,lookahead,lookbehind,grepl
I have 3 words: x, y, and z, from which two compound words can be built: x-y, and y-z. In naturally occuring text, x, y, and z can follow each other. In the first case, I have: text="x-y z" And I want to detect: "x-y" but not "y z". If...

How to describe an optional negative lookahead in regular expression?

regex,grep,lookahead
I like to get the appointment description of calender entries which a program called khal outputs by using grep. The output of khal looks like this: 20:30-22:30 13.05.2015: Manfred treffen Repeat: FREQ=WEEKLY;BYDAY=WE;WKST=MO 09.05. - 12.05.2015: Britt Besuch In the example I would like to match Manfred treffen and Britt Besuch....

Parsing text between quotes with .NET regular expressions

c#,.net,regex,lookahead,lookbehind
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 following named captures: name:"foo" value:"bar" name:"name" value:"John \""The Anonymous One\"" Doe"...

Regex for web extraction. Positive lookahead issues

regex,lookahead
Below is an example of some data I'm using. I've read a number of posts involving this topic, as well as tried for a while on regex101. BotInfo[-]: Source IP:[10.1.1.100] Target Host:[CentOS70-1] Target OS:[CentOS 7.0] Description:[HTTP Connection Request] Details:[10.1.1.101 - - [28/May /2013:12:24:08 +0000] "GET /math/html.mli HTTP/1.0" 404 3567 "-"...

superfluous LOOKAHEAD in javacc causes error?

java,parsing,javacc,lookahead
I have the following TT.jj, if I uncomment the SomethingElse part below, it successfully parses a language of the form create create blahblah or create blahblah. But if I comment out the SomethingElse part below, but retain the LOOKAHEAD, javacc complains that the lookahead is not necessary and "ignored", but...

Lookahead Behaviour

regex,r,lookahead
How can you make the lookahead non-greedy? I would like the first case not to match anything (like the second case), but it returns "winnie". I guess because it is greedily matching after the "the"? str <- "winnie the pooh bear" ## Unexpected regmatches(str, gregexpr("winnie|bear(?= bear|pooh)", str, perl=T)) # [1]...

Regex to create a group from an entire line, or just up to a given token

javascript,regex,lookahead,end-of-line
I'm using a JavaScript Regex Engine. The regex ^(.*?)\s*(?=[*\[]).* will capture a group containing all the characters up to a [ or * character. It works well with these lines, matching the entire line and capturing the first section: This should be captured up to here[ but no further] This...

Regex that grabs variable number of groups

python,regex,lookahead
This is not a question asking how to use re.findall() or the global modifier (?g) or \g. This is asking how to match n groups with one regex expression, with n between 3 and 5. Rules: needs to ignore lines with first non-space character as # (comments) needs to get...

Regex that matches string before comma unless the text contains a clasped list that is also separated by comma

ruby,regex,lookahead
Let's say this is my text: "a, b, c (1, 2, 3), d, f (x, y)" I want to match every point of the enumeration but I also don't want the sub list comma interpreted as a terminating character. I want a regex to extract the following matches: a b...

Lookahead in regular expression

regex,r,lookahead
I am trying to use a regular expression in order to extract the part of a string before the first " / " occurrence. In the following example the initial string is "Atomic grouping / possessive qualifiers / conditional and recursive patterns" and i want to get "Atomic grouping" library(stringr)...