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
0 answers

How to exclude files names that have exact match with regex and to support multiple patterns?

I have a program that transfers files from one folder to another (and does some manipulation on those files), I am trying to create a regex to exclude certain files based on file name and extension, this also needs to support multiple entries that…
0
votes
2 answers

Conditional Python regex to match URLs that may contain a second colon

I am trying to match URLs or relative paths that do not contain a second colon (after the one in the protocol, e.g., http(s)://). I want to reject URLs of the form https://en.wikipedia.org/wiki/Special:BookSources/0-8018-1841-9 or paths of the…
tat
  • 321
  • 1
  • 19
0
votes
0 answers

How to negate a particular pattern in string using regex?

I have a string where i want to extract a particular pattern only. x<-c("N4553","3805U","celeron N4553","applheddd") gregextract <- gregexpr('\\bceleron\\b|\\bN[0-9]+\\b',x,perl=TRUE) size1<- regmatches(x,gregextract,invert = FALSE) It extracts…
Richie
  • 171
  • 1
  • 5
0
votes
1 answer

Exclude specific name in regex

I have multiple directories with names like app1.6.11, app1.7.12, app1.8.34, test1, test2. I want to match regex for all the directories which start with app and to exclude app1.8.34. I have tried: ^(app.+)[^(app1.8.34)]
Jeet
  • 185
  • 1
  • 2
  • 10
0
votes
1 answer

Regular expression containing all the text but a certain regular expression

I come from here Regex: match everything but But they only say how to get a Regex containing all but some string. What im trying to do is finding a regular expression that matches me all the text but this ^([\S+" "?]+" "@[a-zA-Z0-9_]{1,15})$ (or any…
Guillem
  • 144
  • 4
  • 13
0
votes
2 answers

Regex Grouping and extraction of particular group based on regex look behind

I want to extract digits after 'ID' occurrence in the following text This is how I am able to get it. import re txt="Recharge done on 28-12-2017 04:57PM,MRP:Rs9.00,GST 18% payable by Company/Distributor/Retailer:Rs1.37, ID 147894886." # 'ID' need…
0
votes
1 answer

Get part of url with conditions

Based on this example: http://example.com/cat1/tag/this%20is%20page/cat2, i need to make a regex to get /tag/ only if this pattern is followed or preceded by other segments, not if is alone. The result that i need is always:…
Kouga
  • 27
  • 1
  • 9
0
votes
1 answer

Find & replace text not already inside an tag - RegEx .Net

I am working with XML data in .NET from the Federal Register, which contain many references to Executive Orders & chapters from the U.S. Code. I'd like to be able to hyperlink to these references, unless they're already inside of an tag (which…
David
  • 1
  • 1
0
votes
1 answer

Remove segments and replaces in url with regex

I've this exercise: Having these links 1. http://example.com/cat1/subcat3/subcat4/tag/this%20is%20page/asdasda?start=130 2. http://example.com/cat1/subcat3/subcat4/tag/this%20is%20pageasdasd 3. example.it/news/tag/this%is%20n%page?adsadsadasd 4.…
0
votes
1 answer

Accept specific word but negate if you have another specific word together

I know that I can negate a specific word with negative lookahead - so in my example how do I negate an actual "/checkout/payment" but accept only when have the word "/checkout/"? What I need exactly: /itempage/ - not match /product/model - not…
0
votes
3 answers

regex for match all tag and extract the "src" attribute

i want, with a regex, find all img tag into html document and extract the content of the src attribute. This is my regex (see online https://regex101.com/r/EE08dw/1): [^>]+?)src=('|")?(?[^\2>]+)[\2]?(?[^>]*)> On a test…
Simone Nigro
  • 4,717
  • 2
  • 37
  • 72
0
votes
2 answers

Regex replace everything except match

I would like to keep just words that start with '@' and continue with letters or dots. Basically I have done opposite that I can match such a words but don't know how to match everything besides this match. So basically just keep those that starts…
John Snow
  • 153
  • 7
0
votes
2 answers

In a given string develop a pattern to match any occurrence of letter “b” , Where it should not follow letter “a”

In a given string develop a pattern to match any occurrence of letter “b” , Where it should not follow letter “a”. For example: abc or ab should not match, b ba, bb, cba should match. I tried the following regex: **/(?!.*ab)(?=.*b)^(\w+)$/** The…
Bk.Neo
  • 61
  • 1
  • 7
0
votes
3 answers

Replace all occurrences of a white space from string except the first occurrence using Regex in C#

The input string having multiple whitespaces, and the result should have only one white space left, other whitespaces must be replaced with string.Empty Input String: +1 580 5691 234 or (435) 772-5992 Output String: +1 5805691234 or +1…
CodeConstruct
  • 290
  • 3
  • 17
0
votes
3 answers

How to Combine dot(.) that has no spaces thereafter? [Regular Expression]

This is my code [^\.!\?]+[!\?\.] I want to separate every sentence perfectly in a post. I am using javascript regex. The problem is when the dot(.) is between characters without spaces so they are separated when they should be merged. For…