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

Regex extracting number with connecting dot and hyphen

Lets say I have the following string:
-18.9%
What want to extract is -18.9 I currently have [^0-9.-]+ in javascript But that will include…
Tronik
  • 47
  • 6
0
votes
1 answer

Regex for a field not equal to zero

I want to add a validation to input field so that it won't accept zero as valid input. I want to use a regex for that, so it allows everything except zero. I tested a couple of regex e.g. ^((?!0).)*$ but did not quite get the thing that I was…
Mahtab Alam
  • 1,810
  • 3
  • 23
  • 40
0
votes
2 answers

regular expression to exclude if preceded by not or no

How do i write regular expression to find word bad which is not preceded by words not or no. In the example below I should find Line 1 and Line 4. Line 1: a bad rider Line 2 : apple is not bad Line 3 : there is no bad remarks. Line 4 : no…
snowrock
  • 161
  • 1
  • 1
  • 8
0
votes
2 answers

Regex Pattern match to find and replace

I am trying to create a regex pattern to find and then replace my IMG src tags in my HTML template. Essentially, the pattern should find the contents of the src: And then replace it as such: none In above code source is always same data-lazy-src is…
Harsh
  • 41
  • 6
0
votes
2 answers

Regular expression to match with optional following text

I'm very new to regular expressions and I need some help finding the correct regular expression. I have a text file of the form: apple 4 bananas 5 bananas 5 7 apple 3 apple 6 bananas 3 bananas 4 5 apple 3 bananas 9 I am looking for a regular…
Josh M.
  • 11
  • 2
0
votes
1 answer

How use preg_match_all to check href for a value

Using the simple_html_dom_parser, I am trying to extract the teamId number from the anchor tags href attribute, using regular expression to check if the table cell has an anchor tag. $rowData= array(); foreach($table->find('tr') as $row ){ …
0
votes
2 answers

Regex to get a combination of constant and pattern

I am working on a regex which can help me in replacing a pattern in string. The string that I have in stream is very long and after applying the regex(Find the pattern and then replace with constant value) I have to carry forward the string into my…
Vikas Kumar
  • 87
  • 2
  • 18
0
votes
5 answers

Reg Ex negation

I am using .Net. I want to match last name which has charecters other than a-z, A-Z, space and single quote and len of charecters should not be between 1-40 . The string that has to be matched is a XML look like this…
Amzath
  • 3,159
  • 10
  • 31
  • 43
0
votes
1 answer

RegEx to match against HTML tags with certain attributes

I’m trying to write a RegEx that matches an opening HTML tag with a class attribute on it. Just like the following:
gosseti
  • 965
  • 16
  • 40
0
votes
1 answer

Regular expression non-greedy word capture

Starting with the following string: and worda1 worda2 ... wordan and wordb1 wordb2 ... wordbn The ... is not literal, but means that other words could also be there. And the words could be anything but 'and'. I'd like to capture wordb1 wordb2…
0
votes
1 answer

Only match specific domain

I got the following string: Contact Us | Privacy Policy

J. Doe
  • 677
  • 7
  • 20
0
votes
1 answer

Regular expression for search methods private or public not containing comments

I have a big pieces of code, so I want to find a regular expression to find all places where my code does not have engineer in the comment before the public or private, for example: using System; using System.Collections.Generic; using…
jrpz
  • 73
  • 1
  • 8
0
votes
3 answers

What is the regex to match a string not containing more than x consecutive characters

I want to match strings that do not contain more than 3 of the same character repeated in a row. So: abaaaa [no match] abawdasd [match] abbbbasda [no match] bbabbabba [match] Yes, it would be much easier and neater to do a regex match for…
Co7e
  • 1,008
  • 10
  • 17
0
votes
0 answers

RegEx to invalid a string if it contains a certain word in Javascript

I am making a validation for my invoiceId which basically allows all letters and numbers and the dash character (-), and it doesn't allow the word draft in any part of the string, for example: Valid cases: 123456…
0
votes
1 answer

Regex to match parts of line and negative-lookup the rest of the line (not match a word)

Is there a regex, that matches hahafooblababla and does not match hahafooblabarbla Because I am looking for ...foo... and don't want to have ...bar... anywhere after the ...foo... haha and bla symbolize junk/noise. UPDATE: At first I tried…
user1414745
  • 1,317
  • 6
  • 25
  • 45