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).



You should be able calculate the difference yourself.


If the regex engine supports lookahead assertion, you could use


but this would probably be less efficient.

Monday, December 12, 2022

The Arabic regex is:


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

So, in JS it will be


See regex demo

Tuesday, October 11, 2022

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

To test if character is_numeric, use:


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

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
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 :