This question already has answers here:
Regex: negative lookbehind AND negative lookahead
(3 answers)
Closed 5 months ago.
so I have this regex:
(?<![a-zA-Z])(0)(?![a-zA-Z])
it caches "0"s that don't have a letter before AND no letter after
I want to catch "0"s that either don't have a letter before OR don't have a letter after.
Regex101
You could use the OR operator |:
(?<!\w)0|0(?!\w)
regex101
Related
This question already has answers here:
Regex: match everything but a specific pattern
(6 answers)
Closed 2 years ago.
^-?[0-9][0-9]{0,2}$
I have this regex but numbers but it allows -0, Any solution?
You may use a negative lookahead assertion to disallow certain match:
^(?!-0$)-?[0-9][0-9]{0,2}$
RegEx Demo
Take note of (?!-0$) that says fail the match if we have -0 and end anchor after matching start anchor ^.
This question already has answers here:
Understanding the negated character class
(3 answers)
Negative lookahead in regex to exclude percentage (%) in R
(3 answers)
Closed 2 years ago.
I have the string '05/'. If I write the pattern \d+[^\/]{1}, why does it still match the '05' part of the string? Shouldn't it be fully rejected since there is no match on the 3rd char requirement?
This question already has an answer here:
Regex return seven digit number match only
(1 answer)
Closed 4 years ago.
I have a string: 12345 XD Hi12345678ab666666cd987654321.
I want to obtain 12345678 and 666666 and discard 98765432 or 87654321, which I could do that by lookahead and lookbehind like (?<!\d)\d{6,8}(?!\d).
The problem is VBA do not support lookbehind.
How do I rewrite the pattern to obtain what I want?
A simple alternative would be to match \D and use a capturing group for the numbers.
(?:\D|^)(\d{6,8})(?!\d)
Demo
You can access the first capturing group with match.Submatches(0)
This question already has answers here:
How to match the first word after an expression with regex?
(7 answers)
Closed 7 years ago.
What RegEx would match the word (including special characters) right after a keyword?
E.g. In the following text, using the keyword "equals", the RegEx would match "'1'", "Two" and "3"
Status equals '1' or Status equals Two or Status equals 3
Use a positive lookbehind.
(?<=\bequals )\S+
This question already has answers here:
How to validate phone numbers using regex
(43 answers)
Closed 8 years ago.
Should match the following:-
(222)-333-4444
(010)-123-3435
(100)-454-6565
But Should disallow:-
(000)-000-0000
The only problem is when the input is entered all zeros. Otherwise my regex:-
^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$
works fine__.
Demo
http://regexstorm.net/tester
You can use this negative lookahead based regex:
^(?![0()-]+$)\(?(\d{3})\)?[-. ]?(\d{3})[-. ]?(\d{4})$
RegEx Demo
(?![0()-]+$) is a negative lookahead that says fail the match if matches only [0()-] character till the end.