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
5
votes
1 answer

Negative lookbehind in regex

(Note: not a duplicate of Why can't you use repetition quantifiers in zero-width look behind assertions; see end of post.) I'm trying to write a grep -P (Perl) regex that matches B, when it is not preceded by A -- regardless of whether there is…
std_answ
  • 1,039
  • 1
  • 11
  • 17
5
votes
3 answers

negative lookbehind and greedy quantifiers in php

I'm using a regex to find any URLs and link them accordingly. However, I do not want to linkify any URLs that are already linked so I'm using lookbehind to see if the URL has an href before it. This fails though because variable length quantifiers…
Sean Nilan
  • 1,745
  • 1
  • 14
  • 21
5
votes
5 answers

How can regex ignore escaped-quotes when matching strings?

I'm trying to write a regex that will match everything BUT an apostrophe that has not been escaped. Consider the following: My goal is to write a regular expression that will essentially match the…
JMTyler
  • 1,604
  • 2
  • 21
  • 24
4
votes
3 answers

Problem with negative lookbehind regex capturing

I try to match email addresses but only when they are not preceeded with "mailto:". I try this regular expression: "/(?
boryn
  • 726
  • 9
  • 10
4
votes
2 answers

Tied up in knots with lookbehind and negative lookbehind assertions in regular expressions in Python

I have a Pandas dataframe which has a column of string data that consists of two distinct parts separated by forward slash. I want to extract text patterns from the 'right hand side' of the string but not if a particular string pattern is present.…
user1718097
  • 4,090
  • 11
  • 48
  • 63
4
votes
2 answers

Regex for matching a word, unless the previous line ends with a word

I have a text which contains many sentences, separated by newlines and arbitrary whitespace: Some thing. Some other text. Some line. Some additional text. Some stuff. Some additional text. Some additional text. How do I match only those…
Lou
  • 4,244
  • 3
  • 33
  • 72
4
votes
2 answers

Why is this negative lookbehind being considered a successful regex match?

I would expect that this simple text string would not be considered a match: xyz@xyz:~$ echo xy | perl -n -e 'print if /y(?
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
4
votes
3 answers

Making Regular Expression more efficient

I'm attempting to determine the end of an English sentence (only approximately), by looking for "!", "?" or ".", but in the case of "." only when not preceeded by common abbreviations such as Mr. or Dr. Is there any way to make the following Regular…
Joshua
  • 6,643
  • 15
  • 55
  • 76
4
votes
1 answer

Javascript regex to exclude if inside brackets

I'm trying to split an expression string on the characters +*() but I need to only split there if they are not inside brackets. I am struggling to create the correct regex for this task. Example: .N.TESTARRAY[INT1+2] + ONLINE * STACKOVERFLOW I…
Joe Jankowiak
  • 1,059
  • 12
  • 37
4
votes
2 answers

Regex negative match in middle of string

I have these strings (checking every line separately): adminUpdate adminDeleteEx adminEditXe adminExclude listWebsite listEx Now I want to match anything that starts with admin but does not ends with Ex (case-insensitive) So after applying regex I…
Justinas
  • 41,402
  • 5
  • 66
  • 96
4
votes
2 answers

Regex lookahead/lookbehind comments

I have a snippet from a config file that I need to be able to match the specified string quote contents, but only when they're not commented out, here's my current regex: (?
bruchowski
  • 5,043
  • 7
  • 30
  • 46
4
votes
2 answers

Find word that does not come after another word with RegEx

What is the RegEx pattern I should use in order to match a specific word that does not come after another specific word? For example: I'm looking for an "abc" that does not come after "xyz", so the following will match: xxabc p abc And the…
ml123
  • 1,059
  • 2
  • 12
  • 27
4
votes
6 answers

How do I match part of a string only if it is not preceded by certain characters?

I've created the following regex pattern in an attempt to match a string 6 characters in length ending in either "PRI" or "SEC", unless the string = "SIGSEC". For example, I want to match ABCPRI, XYZPRI, ABCSEC and XYZSEC, but not…
Rich
  • 896
  • 6
  • 15
4
votes
4 answers

Combine negative lookahead and behind regex

I would like a regex which will split a string at every "." except if the "." is preceded AND followed by an number. example: "hello world.foo 1.1 bar.1" ==> ["hello world","foo 1.1 bar", "1"] I currently have: "(?
user1110718
  • 217
  • 1
  • 3
  • 11
4
votes
2 answers

Regular expression - Negative look-ahead

I'm trying to use Perl's negative look-ahead regular expression to exclude certain string from targeted string. Please give me your advice. I was trying to get strings which do not have -sm, -sp, or -sa. REGEX: hostname…
Jaeh
  • 609
  • 1
  • 6
  • 19
1
2
3
13 14