If you recently updated your server to PHP 7.3, you might have seen this error message:
Compilation failed: invalid range in character class at offset . . .
This error is due to update in PHP 7.3 and how it handles regular expressions.
Error: Compilation failed: invalid range in character class at offset
I encountered this error on a WordPress site running WP Bakery Page Builder / visual composer 5.6 plugin. The error said:
Compilation failed: invalid range in character class at offset 11 in /home/path/public_html/content/plugins/js_composer/include/autoload/hook-vs-grid.php on line 163
The plugin came with the theme we were using and the theme was at latest version but had visual composer version 5.6 only, thus we didn’t have any other option than to fix this error, otherwise we would have to purchase the wp bakery visual composer latest update (5.7).
This post will help you fix this issue in visual composer or any other PHP plugin or code if you’re experiencing it.
How to fix Error Compilation failed: invalid range in character class at offset
To simply fix this error in visual composer for WordPress, go to file:
/wp-content/plugins/js_composer/include/autoload/hook-vc-grid.php
And edit line 86, from:
. '([\\w-_]+)' // 2: Shortcode name
To:
. '([\\w\-_]+)' // 2: Shortcode name
Save the file and you’re done!
We changed the – to \- (if you’re wondering).
Explanation
The – here is intended to match the literal – character. However it’s also used for giving a range, like 1-7 or so. PHP 7.3 expects us to be more clear in this situation if we want to use the literal – character. So what we did here is that we escaped the – character by adding a backslash to it like this: \- and it fixed our code.
Note that we don’t need to make that change everywhere in our code. We need to do that where PHP 7.3 more likely takes this literal character as a range in that statement. However it’s a good practice to escape it more often.
You can use this logic to fix this error in any other of your scripts too. If you’re confused and want my help to fix it, please let me know.
THANK YOU!
You’re welcome! :)
Thank you work for me
Thank you! Just used it on my website, this saved me a big headache!
Welcome Gabrielle. I’m glad to know that it was helpful :)
It’s Work!! Well Done. Thank you..
Can you pls tell me that my visual composer is not showing backend editor structure.
There can be many reasons for this issue. We can only confirm after looking into your specific case. I have sent you an email please check that and let me know if you want me to look into this.
Great! just fixed
Thank You
Thanks! The error was loading in between new post/product creations on a WP WooCommerce site with WP Bakery. Outside of showing the error between page loads, everything worked correctly, but this seems to have resolved the error showing. Much appreciation!
Thanks man!
It worked for me as well…
Thanks mate, it saves my day :)
You’re welcome Waqas :)
I have the same problem, could you solve it?
OMG, I do not know how to say thank you. I was looking for a solution for more than 3 days and I could not find anything. you saved me, Bro.
I have another problem like Sagar said so. My visual composer is not showing the backend editor structure. Could you please help me in this case?
Thank you again.
Sure I can help. Please check your email.
Hi
VC backend editor for my website is not working. Can you please help us to fix this issue?
Thank you.
Please check your email.
Warning: preg_match(): Compilation failed: invalid range in character class at offset 12 in \wp-content\plugins\js_composer\include\classes\shortcodes\vc-basic-grid.php on line 177
vc-basic-grid.php: $id_pattern = ‘/’ . $this->grid_id_unique_name . ‘\:([\w-_]+)/’;
hook-vc-grid.php . ‘([\\w-_]+)’ // 2: Shortcode name
can you please guide me in this thanks
this is the error i am geting i have changed the – to \- but its not working or i change the same on both file.
Please check your email.
I also have the same issue at vc-basic-grid.php: $id_pattern = ‘/’ . $this->grid_id_unique_name . ‘\:([\w-_]+)/’; ln 177. Kindly assist.
Please check your email.
Hello!
I’m having the same issue with vc-basic-grid.php.
$id_pattern = ‘/’ . $this->grid_id_unique_name . ‘\:([\w-_]+)/’;
Changed to ‘\:([\w\_]+)/’ and I no longer get the error, but the grid doesn’t load.
Please help!
Thanks,
Darrell.
Please check your email. If you want our services to fix it for you please let us know.
Genius. Thanks!
Worked! I just googled the error, and so many people saying it worked so I went for it.
thanks man.
Thanks Its helpful
Excellent, thanks.
Its worked help me a lot love you
Hi,
I have the same problem – where can I find the file to update? I am currently working with a duplicate website on my computer locally meanwhile the old version is still live.
Which theme are you using? And what exact error are you getting?
If you want to hire me to solve it for you, then please let me know.
Had to leave a comment to say thank you. Only recently I noticed this error pop-up, I guess after a mandatory PHP update
Wow you really helped a lot!
Dear Nabtron,
I do not have special IT skills, but I understand this is the solution to the error (I just updated PHP version 7.3 and this WP theme use Visual Composer).
How do I access the file you mention? ….
To simply fix this error in visual composer for WordPress, go to file: /wp-content/plugins/js_composer/include/autoload/hook-vc-grid.php
THANK YOU!
You can access this file via ftp (filezilla) or via ssh or file manager provided by your hosting service provider. Please let me know if you want our services to fix it for you.
Thankyou for saving my time. :)
work like a charm. Now I can create blog post now
Thank you so much ! You helped me a lot.
Morad.
Cheers from Lille, France !
oh my God . god bless you . thank you so much
Great!! Thank you!!!
Work for me!! “\”
Thank you for the solution… It worked perfectly…
That works for me too. Thank you, man.
Hey my problem is solved but the iframe is not showing, although when i am moving my cursor its showing that something is there along with url showing up at the bottom of the screen. But can’t see anything
This can be due to zero/auto width and height of the iframe. Try adding width and height to your iframe and see.
THANK YOU FOR POSTING THIS FIX.
Worked for me too, thanks a lot !!!
Worked for mee too. Thanks.
Worked for me, thank you