Viewed   60 times

How can I use the negation within square brackets as an exception, to find e. g. everything between a-z except for the the range from m-o? [a-z^m-o]?

By the way: it's not for the sake of this example that I ask, but to be able to exclude ranges within ranges, or even single letters within ranges. I am pretty much aware that in this example it can be calculated.

I use the Zend engine (PHP).

 Answers

4

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.

Monday, December 12, 2022
5

The Arabic regex is:

[u0600-u06FF]

Actually, ?-? is a subset of this Arabic range, so I think you can remove them from the pattern.

So, in JS it will be

/^[a-z0-9+,()/'su0600-u06FF-]+$/i

See regex demo

Tuesday, October 11, 2022
5
.(?=.*.)

Matches a dot (.), which there must be another dot following it ((?=.*.)).

(This assumes the regex engine supports lookahead, e.g. PCRE, Python, etc.)

Friday, September 2, 2022
 
1

To test if character is_numeric, use:

is_numeric($a[$i-1])

As below:

$s = "rfewr545 345b";
for ($i = 0; $i < strlen($s); $i++){
   $char = $s[$i];
   if (is_numeric($char)) {
      echo $char . ' is a number';
   } else {
      echo $char . ' is a letter';
   }
}
Tuesday, November 8, 2022
3

For this PHP regex:

$str = preg_replace ( '{(.)1+}', '$1', $str );
$str = preg_replace ( '{[ '-_()]}', '', $str )

In Java:

str = str.replaceAll("(.)\1+", "$1");
str = str.replaceAll("[ '-_\(\)]", "");

I suggest you to provide your input and expected output then you will get better answers on how it can be done in PHP and/or Java.

Sunday, October 9, 2022
 
haodong
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :