preg_match(): Compilation failed: invalid range in character class at offset 20 while reloading the pages
ItsAnubhav opened this issue · 13 comments
ErrorException (E_WARNING)
preg_match(): Compilation failed: invalid range in character class at offset 20
This message appeared when
1> I logged in and redirected to the dashboard.
2> When I tried to reload the page.
C:\xampp\htdocs\laravStart\vendor\laravel\framework\src\Illuminate\Routing\Matching\UriValidator.php
namespace Illuminate\Routing\Matching;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
class UriValidator implements ValidatorInterface
{
/**
* Validate a given rule against a route and request.
*
* @param \Illuminate\Routing\Route $route
* @param \Illuminate\Http\Request $request
* @return bool
*/
public function matches(Route $route, Request $request)
{
$path = $request->path() == '/' ? '/' : '/'.$request->path();
return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
}
}
Arguments
"preg_match(): Compilation failed: invalid range in character class at offset 20"
Hi buddy,
Can you please show me your web.php route file ??
Here it is
<?php
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::get('invoice', function(){
return view('invoice');
});
Route::get('{path}',"HomeController@index")->where( 'path', "/^[a-z0-9]([0-9a-z_-\s])+$/i" );
Hi there, The problem is with your regular exp in the last line. it should be
Route::get('{path}',"HomeController@index")->where( 'path', '([A-z\d-\/_.]+)?' );
If you want to know why, there is the answer
preg_match(): Compilation failed
Hello, Thanks for the free tutorial.
I am currently following this and i am using Laravel 5.8 but i get the below error when i directly enter the url;
/Users/killasites/Desktop/ezyweb/vendor/laravel/framework/src/Illuminate/Routing/Matching/UriValidator.php
namespace Illuminate\Routing\Matching;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
class UriValidator implements ValidatorInterface
{
/**
* Validate a given rule against a route and request.
*
* @param \Illuminate\Routing\Route $route
* @param \Illuminate\Http\Request $request
* @return bool
*/
public function matches(Route $route, Request $request)
{
$path = $request->path() === '/' ? '/' : '/'.$request->path();
return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
}
}
Please help. My web.php file is as below;
name('home'); Route::get('{path}',"HomeController@index")->where( 'path', '([A-z\d-\/_.]+)?' );I think, u need to follow, with the exact same laravel version, on the tutorial, 5.6, i used to follow with 5.7, and it's not going well, then with 5.6 it's good.
Thanks, i found a solution. It's by escaping the - with -
It worked.
Hi, Hujjat I have the same problem when I'm using php 7.3, in php 7.2 works fine, I was reading about the changes on php 7.3, and the PCRE was change by PCRE2.
have you checked your application using php 7.3?
Hi. I had a same problem and i solved it. My php version is 7.3.
I added \ after d
The final code is:
Route::get('{path}','HomeController@index')->where( 'path', '([A-z\d-/_.]+)?' );
Thanks, i found a solution. It's by escaping the - with -
It worked.
More details please
Please try this one.
([A-z\d\-\/_.]+)
escaping the "-" .. and it should work properly for PHP 7.3
I am using Laravel 5.8 with php 7.1
and web.php file following code resolved this issue for me
/* Resolve Direckt Links Issue Between Laravel Router and Vue Router */
Route::get('{path}','HomeController@index')->where('path','([A-z\d-/_.]+)?');
Please try this one.
([A-z\d\-\/_.]+)
escaping the "-" .. and it should work properly for PHP 7.3
thank you it work with me @mailightkun