Regular Expression: Find Range Except for One Letter or a Range

Regular expression: find range except for one letter or a range

You should be able calculate the difference yourself.

[a-lp-z]

If the regex engine supports lookahead assertion, you could use

(?![m-o])[a-z]

but this would probably be less efficient.

Regex: How to match a range of characters except another range

A simple way is to add a negative lookahead for what you don't want.

^[a-z0-9](?!.*[A-Z_])[ -~]*$

But it's also possible to just split up the ranges, based on the ascii-table

^[a-z0-9][ -@\[-^`-~]*$

It's just a bit less easy to understand at a first glance.

Excluding some character from a range - javascript regular expression

To exclude k or p from [a-zA-Z] you need to use a negative lookahead assertion.

(?![kpKP])[a-zA-Z]+

Use anchors if necessary.

^(?:(?![kpKP])[a-zA-Z])+$

It checks for not of k or p before matching each character.

OR

^(?!.*[kpKP])[a-zA-Z]+$

It just excludes the lines which contains k or p and matches only those lines which contains only alphabets other than k or p.

DEMO

RegEx: number range excluding specific number

You may use a negative lookahead assertion in your regex:

~\bAM19/0(?!803)[678]\d{2}\b~

RegEx Demo

Here we have a negative lookahead (?!803) after matching 19/0 which will fail the match if 803 appears right after 19/0 in input.

Also note that by using an alternate regex delimiter ~ you can avoid escaping / in your regex.

Excluding some characters from a Regular Expression range

.Net supports another notation for Character Class Subtraction:

[\u0D80-\u0DFF-[\u0D92]]*

Example (using the .Net engine): http://regexstorm.net/tester

How to match range of numbers excluding first digit

This regex enforces the uniqueness of X, Y and Z:

([1-9])((?!\1)[1-9])\10((?!\1|\2)[1-9])\3\2

...but there's no way to enforce their ordering with a regex.


About the regex:

([1-9]) captures the first digit in group #1. That's the first X in your template.

((?!\1)[1-9]) captures the second digit in group #2, but only after the negative lookahead confirms that it isn't the same as the first digit. That's the Z value.

\1 matches the third digit, assuming it's the same as the first digit.

0 is obvious

((?!\1|\2)[1-9]) represents the Y value, so we have to confirm that it's not the same as either of the other two captures. It's captured in group #3.

\3 matches the same digit again; that's the second Y.

\2 matches another of whatever the Z value was, and Bob's your uncle!

Getting back to that 0 again, there's one caveat that I overlooked. If there happen to be ten or more capturing groups in the regex, \10 could be interpreted as a backreference to group #10. It's a good idea to break up that kind of thing whether it needs it or not.

Many regex flavors provide alternative notation that isolates the group reference, like \g<1> or ${1}. Not knowing what flavor you're using, I'll use square brackets to isolate the zero instead (i.e., turn it into a single-element character class):

([1-9])((?!\1)[1-9])\1[0]((?!\1|\2)[1-9])\3\2

Regular expression to select all characters except letters or digits

Below is a quick summary of regexps and how you can group together a query set using the commands below. In your case place the ^ inside the [a-zA-Z0-9] to achieve the desired result.

  .   Single character match except newline
"." Anything in quotations marks literally
A* Zero or more occurrences of A
A+ One or more occurrences of A
A? Zero or one occurrence of A
A/B Match A only if followed by B
() series of regexps grouped together
[] Match any character in brackets
[^] Do not match any character in brackets
[-] Define range of characters to match
^ Match beginning of new line
$ Match end of a line
{} Cardinality of pattern match set
\ Escapes meta-characters
| Disjunctive matches, or operation match

For excepting some character in Range

You can use:

(?:(?![orz])[a-z])+

Demo & explanation

Regex Match on any Number Except

I think you can update your regex adding a word boundary \b after the group to:

^(?!(0|1|2|3|4|5|6)\b).*

You could also write this shorter replacing the or statements with a character range from 0-6 like:
^(?![0-6]\b).*



Related Topics



Leave a reply



Submit