Preg_Match(): Compilation Failed: Invalid Range in Character Class At Offset

Compilation failed: invalid range in character class at offset 4

Escape the hyphen:

if (!preg_match("/^[\w\-:]+$/", $tag)) { 

or put it at the beginning of character class:

if (!preg_match("/^[-\w:]+$/", $tag)) { 

or at the end:

if (!preg_match("/^[\w:-]+$/", $tag)) { 

PHP 5.6.10 - preg_match(): Compilation failed: invalid range in character class at offset 100

In class - is a range operator you need to escape it with \

[a-zA-Z0-9_\-\s]

preg_match(): Compilation failed: invalid range in character class at offset 20

For php version is 7.3 and above use \- instead of -, so your final code :

Route::get('{path}',"HomeController@index")->where( 'path', '([A\-z\d\-\/_.]+)?' );
Route::get('{path}',"HomeController@index")->where('path','[\-a\-z0\-9_\s]+');

preg_replace(): Compilation failed: invalid range in character class at offset 11 in Laravel Slug

You have a extra - after \s.

Replace:

$string = preg_replace("/[^a-z0-9_\s-ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]#u/", "", $string);

with

$string = preg_replace("/[^a-z0-9_\sءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]#u/", "", $string);

Or fix it to match your regex, like escaping it \-.

preg_match(): Compilation failed: invalid range in character class at offset 15

The hyphen (-) needs to be escaped because of its position inside of the character class.

Note: Inside of a character class the hyphen has special meaning. You can place it as the first or last character of the class. In some regex implementations, you can also place directly after a range. If you place the hyphen anywhere else you need to precede it with a backslash in order to add it to your character class.

if(preg_match("/^[a-zA-Z\s,.'\-\pL]+$/u", $name)) { ...
^^

You could write the regular expressions as follows:

if(preg_match("/^[\pL\s,.'-]+$/u", $name)) { ...


Related Topics



Leave a reply



Submit