Questions tagged [lookahead]

Lookahead is a zero-length assertion used in combinatorial searches and parsing.

Lookahead is a zero-length assertion used for parsing text ahead of the current point. This is frequently used in regex to assert if a match is possible or not. Further explanation in this tutorial.

The term is also used in combinatorial search to determine how deep the graph representing the problem is explored which allows for better control of the search algorithm's time. Wikipedia

376 questions
5
votes
1 answer

Complex lookahead/not-greedy regex

I have the following string: (it is all on a single line)
Noam Rathaus
  • 3,695
  • 1
  • 22
  • 33
5
votes
2 answers

Regex with negative lookahead across multiple lines

For the past few hours I've been trying to match address(es) from the following sample data and I can't get it to work: medicalHistory None address 24 Lewin Street, KUBURA, NSW, Australia email …
n1te
  • 944
  • 3
  • 11
  • 20
4
votes
1 answer

Regular Expression which matches fixed length chunk with variable length elements

I'm writing some regex to match lines which contain numeric elements padded with spaces, like -2.45. The regex for this is simple enough: /(\s*-?\d+\.\d{2})/ However, I have the additional constraint that the whole chunk is limited to exactly seven…
4
votes
3 answers

Regex to match only innermost delimited sequence

I have a string that contains sequences delimited by multiple characters: << and >>. I need a regular expression to only give me the innermost sequences. I have tried lookaheads but they don't seem to work in the way I expect them to. Here is a test…
amphetamachine
  • 23,162
  • 10
  • 51
  • 68
4
votes
3 answers

How do I use look-ahead in regex to match on no character?

I've got a set of regex's within a function that are working rather well for me, but I've encountered a new pattern where they fail. This function fails when there are no more characters in the string. For example my function matches and replaces…
user56512
4
votes
1 answer

VST lookahead and setInitialDelay()

I think I need to implement a lookahead system in my VST but have never done it before. I know setInitialDelay(foo) is placed in the constructor and then you buffer audio but I'm not sure were a read from for the 'current' audio and for the…
Forge_13
  • 113
  • 1
  • 10
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
2 answers

Regex needs to match alphanumeric string with min of one number look ahead only checks second postion

I have been trying to solve this problem for a bit now and have had to turn to asking you fine people. I have found the following regex pattern many times and from what I have read it should work but doesn't actually seem to…
Fresh
  • 183
  • 10
4
votes
2 answers

C# - Negative Lookahead doesn't seem to work

Working in C# .Net 4.5 I need an expression that will look through a string and fail the match if the string has two or more capital characters anywhere in the string. What I think should be the correct pattern is this: (?![A-Z]{2,})\w Note: tried…
user1255276
  • 521
  • 1
  • 5
  • 17
4
votes
2 answers

RegExp exercise: reluctant quantifier with a lookahead assertion

Can you explain me how this works? Here is an example: