Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no stack', reason: 'Unhandled JS Exception: Invalid regular expression: invalid group specifier name

Tags:

react-native

My app will not boot, it will break with the exception:

Invalid regular expression: invalid group specifier name

no stack
run
    NativeRunnable.java
handleCallback
    Handler.java:873
dispatchMessage
    Handler.java:99
dispatchMessage
    MessageQueueThreadHandler.java:29
loop
    Looper.java:209
run
    MessageQueueThreadImpl.java:232
run
    Thread.java:914

I found that in iOS or android, if I enabled live javascript debug, then the problem will not occur, but why?

The same error I got on xcode and android:

no stack', reason: 'Unhandled JS Exception: Invalid regular expression: invalid group specifier name

I have no idea where to dig? or where to debug? Any one can help?

like image 243
simo Avatar asked Jul 11 '19 13:07

simo


People also ask

What is invalid regular expression flag in JavaScript?

The JavaScript exception "invalid regular expression flag" occurs when the flags, defined after the second slash in regular expression literal, are not one of g, i, m, s , u, or y. What went wrong? There are invalid regular expression flags in the code.

How do I fix invalid regular expression range out of order?

The "Invalid regular expression: Range out of order in character class" error occurs when we forget to escape a hyphen in a character class in a regular expression. To solve the error, specify the hyphen as the first or last character in the regex or escape it.

How to solve this error when using regex?

This error occurs very often when using regex strings, which are quite more difficult to debug as IDE support is minimal. To solve the error, you can either add the hyphen as the first or last character in the character class or escape it. Copied!


2 Answers

Ran into this as well, porting an electron project over to RN. Tracked it down to a lookbehind regular expression, which is supported in Chrome but not Safari (and, apparently, react native) -- see Works in Chrome, but breaks in Safari: Invalid regular expression: invalid group specifier name /(?<=\/)([^#]+)(?=#*)/

Searching for (? in my project led me right to the culprit!

like image 57
lambinator Avatar answered Oct 23 '22 19:10

lambinator


The reason you don't get a stack with this error is because regular expression literals in JavaScript are compiled before the script is executed.

Regular expression literals provide compilation of the regular expression when the script is loaded.

– MDN - Regular Expressions

Unfortunately, this means that the offending regular expression might be anywhere in your code, since all the ES2015 modules are bundled together in react-native applications.

like image 7
Patrick Roberts Avatar answered Oct 23 '22 20:10

Patrick Roberts