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

Regular expression that only matches internal Markdown links without .md extension

I have a project with lots of Markdown files that include internal and external (start with http) links. Some of these internal links don't have a .md file extension and so don't work when rendered outside of Jekyll. Examples: [link text…
janpio
  • 10,645
  • 16
  • 64
  • 107
0
votes
1 answer

slicing only the domain from the domain+TLD combination

I tried to write a Greasemonkey userscript that checks to see if the user is in one of a list of websites. If the user is indeed in one of them, the script will alert: Enough with this domain already! The purpose of the script is to remind the…
OsiOs
  • 39
  • 10
0
votes
3 answers

Matching range without one character with regex

I'd like to create a regex pattern that captures everything within a selfclosing html tag in a string, it is to be used in a php preg_replace that removes all selfclosing tags (that are normally not selfclosing, i.e. div, span etc.) from a html dom…
Rene Jorgensen
  • 169
  • 1
  • 8
0
votes
4 answers

String deleting

hope someone could help me. I am new to python and just learning. I would like to know how to delete unwanted characters from a string. For example, I have some strings in a text file such as 'dogs op care 6A domain, cats op pv=2 domain 3, pig op…
Tikku
  • 137
  • 1
  • 1
  • 6
0
votes
1 answer

How to get the text not in the square bracket using regex c#?

My string looks like below. I want to get Completed from below string. "Completed[TranslationTest]" I want any text which is not in square bracket.
GPK
  • 137
  • 1
  • 1
  • 11
0
votes
0 answers

Match text not surrounded with {{ }} python regex

I am trying to replace text within html files that are part of my angular 2 project. I want to only replace hard-coded text that is not within {{ }} My current code is able to find all the text in all these html files but I am having issues…
Chris Lang
  • 384
  • 2
  • 19
0
votes
0 answers

Need regex replace that only replaces string if not part of a link

I tried to build a regex that finds a string (a persons name) with another (a link), but only if the found string is not already part of a link. So it sould replace: Toya with Toya but never:
Yanco
  • 1
  • 1
0
votes
1 answer

Restricting digits in a regex match

tl;dr: How can I set a count constraint on a particular token in a regex. (regex-exp){constraint:max 10 only digits} I have been trying to find a phone number in a text block. Android platforms Patterns class gives reasonable coverage. But the…
Codevalley
  • 4,593
  • 7
  • 42
  • 56
0
votes
3 answers

Regex: Unable to do negative lookahed

Here's my input text: Intel Core i3-4170 3.7GHz I'm trying to replace 3.7GHz with XXX Here's my pattern: /\s(?=[^\s]+(.*?GHz)$)/ but this matches: i3-4170 3.7GHz if I add the global flag I get what I need in the 2nd group, but I'm not sure if…
Cornwell
  • 3,304
  • 7
  • 51
  • 84
0
votes
1 answer

Match CSS selector that doesn't start with selector

If i have a css file, like this (for example): div { color: red; } a{color: red}.someClass {color: red} .someOtherClass { color: red; } @media (max-width: 767px){ div { color: green; } [data-module="123"] .someOtherClass { color: green;…
0
votes
2 answers

Regex negation for two consecutive numbers

I'm trying to create a regex that blew my mind. How do I make the regex negation below when I have two consecutive numbers? /^([\p{L}\p{N}\. ]+)(, ?| )([0-9-]+[a-z]?)(, ?| |$)(.*)/iu Valid examples: Text Text 123 anything Text Text, 123,…
0
votes
1 answer

RegEx to find ASCII chars

I have a string like this- "CRT\x00\x00\x00\x00\x00G3\x00\x00\x00\x00\x00\x00\x80\x10a\x06\x00\x00\x00\x00\x16@E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x13" I have to convert ASCII chars(CRT, G3, a, @E) to HEX and other chars \x00 to \x09 will be…
Rahul Pandey
  • 435
  • 1
  • 3
  • 13
0
votes
1 answer

RegEx to find partial prefix, but not full prefix followed by a number

My RegEx "FUN(\d{0,20})" captures a bit more than intended. It should return just the number following the specific tag "FUN". How can I alter it to avoid numbers following "WordsEndingWithFUN"? See example below. Case sensitivity is not important…
Oleg Melnikov
  • 3,080
  • 3
  • 34
  • 65
0
votes
2 answers

Regex negative lookahead for url parameter

I'm using this regex to match YouTube playlist URLs and extract the playlist ID: https://regex101.com/r/pO4dS6/31 However, I don't want the regex to match if one of the parameters is "v=" which designates a single video in the playlist. In my…
johnh10
  • 4,047
  • 1
  • 18
  • 30
0
votes
1 answer

Javascript RegEx: capture -A but not A-A. where A is any letter in the set [A-Za-z]. dash followed by letter passes, dash surrounded by letters doesnt

Example: let stringTest = "-this -andthis but-not-this" // match = ['-this', '-andthis'] and ignore "but-not-this" so I want to capture anything defined by -[A-Za-z]+ Here is my attempt to ignore the A-A situation: [^([A-Za-z]-[A-Za-z])] I see…
vampiire
  • 1,111
  • 2
  • 15
  • 27