Questions tagged [negative-lookbehind]

In regular expressions, negative lookbehind checks if the character before the current character does NOT match a certain character.

In regular expressions, negative lookbehind checks if the character before the current character does NOT match a certain character. For example, (?<!a)b matches a "b" that is not preceded by an "a", using the negative lookbehind.

207 questions
178
votes
11 answers

Negative lookbehind equivalent in JavaScript

Is there a way to achieve the equivalent of a negative lookbehind in JavaScript regular expressions? I need to match a string that does not start with a specific set of characters. It seems I am unable to find a regex that does this without failing…
Andrew Ensley
  • 11,611
  • 16
  • 61
  • 73
24
votes
1 answer
22
votes
3 answers

Regular expression using negative lookbehind not working in Notepad++

I have a source file with literally hundreds of occurrences of strings flecha.jpg and flecha1.jpg, but I need to find occurrences of any other .jpg image (i.e. casa.jpg, moto.jpg, whatever) I have tried using a regular expression with negative…
DiegoDD
  • 1,625
  • 4
  • 21
  • 32
21
votes
1 answer

How to use Negative Lookahead in Regex to Delete unwanted Lines

I need help regarding using negative lookahead. I am using Notepad++ and I want to delete all lines except the lines that contain (.*) I tried a couple of things but that didnt work. ^.*(?!).* ^.*(?!.*)
Atif
  • 10,623
  • 20
  • 63
  • 96
19
votes
2 answers

What's the easiest way to get an equivalent to GNU grep that supports negative lookbehinds?

I'm trying to grep through a bunch of files in nested subdirectories to look for regular expression matches; my regex requires negative lookbehind. Perl has negative lookbehind, but as far as I can tell GNU grep doesn't support negative…
Dan Fabulich
  • 37,506
  • 41
  • 139
  • 175
16
votes
2 answers

Lookbehind in regex for VBA?

Is there a way to do negative and positive lookbehind in VBA regex? I want to not match if the string starts with "A", so I am currently doing ^A at the start of the pattern, then removing the first character of match(0). Obviously not the best…
Rich Tier
  • 9,021
  • 10
  • 48
  • 71
15
votes
3 answers

Regular Expression in R with a negative lookbehind

So I have the following data, let's say called "my_data": Storm.Type TYPHOON SEVERE STORM TROPICAL STORM SNOWSTORM AND HIGH WINDS What I want is to classify whether or not each element in my_data$Storm.Type is a storm, BUT I don't want to include…
Jonathan Charlton
  • 1,975
  • 6
  • 23
  • 30
12
votes
2 answers

RegEx: Look-behind to avoid odd number of consecutive backslashes

I have user input where some tags are allowed inside square brackets. I've already wrote the regex pattern to find and validate what's inside the brackets. In user input field opening-bracket could ([) be escaped with backslash, also backslash could…
Wh1T3h4Ck5
  • 8,399
  • 9
  • 59
  • 79
8
votes
2 answers

Regex negative lookbehind and lookahead: equivalence and performance

I need a regex that will select only those URL strings NOT ending with specific extensions like .png or .css. I tested the following: 1) this one using negative lookbehind: (?
Timido
  • 1,646
  • 2
  • 13
  • 16
7
votes
2 answers

Javascript regex: find a word NOT followed by space character

I need javascript regex that will match words that are NOT followed by space character and has @ before, like this: @bug - finds "@bug", because no space afer it @bug and me - finds nothing because there is space after "@bug" @bug and @another …
Zeljko
  • 5,048
  • 5
  • 36
  • 46
7
votes
1 answer

Java regex error - Look-behind with group reference

I'm trying to build a regex that matches exactly two occurrences of a char in a class. This is the regex I made: (?
6
votes
1 answer

Regex negative lookbehind in Ruby doesn't seem to work

Making an argument parser. I want to split a string into an array where the delimiter is ", " except when preceded by "|". That means string "foo, ba|, r, arg" should result in `["foo", "ba|, r", "arg"]` I'm trying to use this regex: (?
tybro0103
  • 48,327
  • 33
  • 144
  • 170
6
votes
2 answers

Are negative lookbehind in regex searches possible in Geany?

Geany's documentation on negative assertions makes it look like they're possible. For reference, this works and gives me results: pcregrep -r "(?
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
5
votes
2 answers

php regex: Alternative to backreference in negative lookbehind

I want to find instances where a captured group does not appear later in the string: aaaBbb = CccBbb <- format is valid, skip aaaDddd = CccDddd <- format is valid, skip aaaEeee = CccFfff <- format is not valid, match this one only So this matches…
Redzarf
  • 2,578
  • 4
  • 30
  • 40
5
votes
3 answers

Regex - Match words in pattern, except within email address

I'm looking to find words in a string that match a specific pattern. Problem is, if the words are part of an email address, they should be ignored. To simplify, the pattern of the "proper words" \w+\.\w+ - one or more characters, an actual period,…
alon
  • 51
  • 1
1
2 3
13 14