Questions tagged [regex-negation]

Regex-negation is an operation performed on a character class that complements its pattern. The result is the character class matching anything not in its class.

Regular Expression negation is typically used to search for patterns that are not desired.

The regular expression language provides some features to handle this, notably negative lookahead/lookbehind, see this tutorial for details.

1926 questions
0
votes
1 answer

How to strip signature image while parsing the email body?

I am only capturing all valid email addresses from email body using below method. public static IEnumerable ParseAllEmailAddressess(string data) { HashSet emailAddressess = new HashSet(); Regex emailRegex…
Savan Patel
  • 357
  • 4
  • 14
0
votes
0 answers

Remove selected character delimited paragraphs using an inverted negative lookahead across multiple lines

I have this input string: string = '''p1 = { s, }, p2 = { {s, }, p3 = { s, }, p2 = { }s, },''' I am trying to replace all paragraphs starting with p2 = { and ending with }, and end up with this new expected output string: p1 = { s, }, p3 =…
tommy.carstensen
  • 8,962
  • 15
  • 65
  • 108
0
votes
1 answer

Simple Negative Lookahead

I get this: import re; print re.findall(r"q(?=u)", "qqq queen quick qeel") > ['q', 'q'] # for queen and quick But I don't get this: import re; print re.findall(r"q(?!=u)", "qqq queen quick qeel") > ['q', 'q', 'q', 'q', 'q', 'q'] # every q…
Nick Lang
  • 469
  • 6
  • 16
0
votes
1 answer

Regex and negative look ahead

I am trying to create some regex patterns that match a website domain. The rules are as below : For France, the URL pattern must have /fr-fr (followed by anything else) after the domain name, ie www.domain.com/fr-fr/anything For Germany, the URL…
0
votes
1 answer

Oracle regexp pattern matching instances of a but not ab

I have seen from from oracle documentation I can do a|b which will match all instances of character 'a 'or character 'b'. I wondered if it was possible in regexp to have 'a' and not 'b' e.g. match all instances of 'a' except where a is followed by…
manic bubble
  • 147
  • 1
  • 3
  • 13
0
votes
1 answer

Regular expression to find the closest pattern match to an html tag

I am checking for a solution to the following problem. I have a text sequence as follows and I would like to extract the contents of the square brackets which is closer to the tag. [P1/1]0(4)0(5)**[P1/432]**…
San
  • 1
0
votes
2 answers

Regex to match decimal point but not .html

I have urls in this format:- /scan/anything/se=hello-world/se=word.html /scan/anything/se=hello-world/se=1.5/ /scan/anything/se=temp-2.5/se=1.5.html I'm trying to match word characters after each se= plus the dash and decimal and capture them. The…
Andrew Smith
  • 117
  • 9
0
votes
2 answers

REGEX in MS Word 2016: Exclude a simple String from Search

So I read a lot about Negation in Regex but can't solve my problem in MS Word 2016. How do I exclude a String, Word, Number(s) from being found? Example: <[A-Z]{2}[A-Z0-9]{9;11}> to search a String like XY123BBT22223 But how to exclude for example…
0
votes
1 answer

regex for a pattern, but also negate a word

Is there a regex for not including a given word, but matching another pattern? I have a simple pattern like the following for grabbing words in a parser I'm using. field = re.compile(r"[a-zA-Z0-9]+") It works fine for the parser to determine…
voodoogiant
  • 2,118
  • 6
  • 29
  • 49
0
votes
2 answers

php PCRE regex to get only the file name that terminates in .txt

so I am trying to form a PCRE regex in php, specifically for use with preg_replace, that will match any number of characters that make up a text(.txt) file name, from this I will derive the directory of the file. my initial approach was to define…
xenador
  • 211
  • 4
  • 15
0
votes
1 answer

Is there a difference between `[^\b]` and `.`?

Is there a difference between [^\b] and .? I was modifying some code created by someone else that included this no-word-boundary-character-class ([^\b]). and am not able to find a difference between that and wildcard . (this is in ruby). My…
Mike H-R
  • 7,726
  • 5
  • 43
  • 65
0
votes
1 answer

Negative Lookahead how use

the texts: 1a2c3 i want all number which does not have a berfore it: 1, 3 I thought it was a classic case of negative lookahead: (?!a)[1-9] but the result is: 1,2,3 What is my mistake? And what way do I need to find only those who have no…
dovid
  • 6,354
  • 3
  • 33
  • 73
0
votes
1 answer

negation classes regex

i wrote this regex for tokenize a text: "\b\w+\b" but someone suggets me to convert it into \b[^\W\d_]+\b can anyone explaing to me why this second way (using negation) is better? thanks
Giacomo Ciampoli
  • 821
  • 3
  • 16
  • 33
0
votes
0 answers

Regex pattern to match and replace a group of x whitespaces before a xml tag with a tab

Note: Just to clear the confusion, I have a parsed XML as String that I would like to apply regex against. Mention of XML in my question simply refer to parsed XML string. I have a XML string processed (PARSED) by Java 7's TransformerFactory with…
Raf
  • 7,505
  • 1
  • 42
  • 59
0
votes
2 answers

Use Regular Expressions to find URLs without certain word patterns

I am trying to write a Regular Expression that can match URLs that don't have a certain pattern. The URLs I am trying to filter out shouldn't have an ID in them, which is 40 Hex uppercase characters. For example, If I have the following…
sparkonhdfs
  • 1,313
  • 2
  • 17
  • 31