Description
The app crashes only on iOS 11.2 giving me unhandled JS Exception: Invalid regular expression: unrecognized character after (?
while not in debug mode.
I've tested the same code on iOS 13 and it works fine. I eventually figured out which regex were causing the problem and I found out that all regex of this type (?<value>\d{2}\/\d{2}\/\d{4})
were causing the crash they are stored as value of a Javascript Object in a separate .js file. I'm asking for a solution that doesn't require changing all the regex.
I don't understand why the behaviour on iOS 13 is different from iOS 11.2.
Also I found a similar issue with lookbehind regex at this link Crash if not in debug on android and iOS.
What I've already tried
Environment
System:
OS: macOS 10.15.2
CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
Memory: 461.18 MB / 16.00 GB
Binaries:
Node: 13.3.0 - /usr/local/Cellar/node/13.3.0/bin/node
Yarn: 1.19.2 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
Android SDK:
API Levels: 28, 29
Build Tools: 28.0.3, 29.0.2
System Images: android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5977832
Xcode: 11.3/11C29 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.6 => 16.8.6
react-native: ^0.60.5 => 0.60.5
npmGlobalPackages:
react-native-cli: 2.0.1
Screenshots
Thanks for reading 🤞
Usually such patterns are used by string-searching algorithms for “find” or “find and replace” operations on strings, or for input validation. React Native codebase same to javascript then syntax are same for both, we have to write and regex in veriable and use javascript test functionalities to validate.
Text component for React Native with regex defined hyperlinks. Heavily inspired from react-native-hyperlink. The difference is that with react-native-hyperlink you use linkify which I couldn't configure to detect arbitrary regex without prefix (e.g. '1:00').
Attach your iPhone with Mac machine. Select your device from the device list. You will see two option view – crash log and open console. click on the open console and you will see the various log of your device. Now open your app and see the log you will get the crash error in the console window or you can search it via Undefined word.
First of all, we try to find a crash report in Xcode. Navigate to Xcode->Window->Devices and Simulators open it. Attach your iPhone with Mac machine. Select your device from the device list. You will see two option view – crash log and open console. click on the open console and you will see the various log of your device.
What i would suggest is if you see that its not working on some specific ios version , check for the ios version and if its ios 13 and above use that regex or try some other regex which works in 11.2.
You can check the iosVersion by
import {Platform} from 'react-native';
const majorVersionIOS = parseInt(Platform.Version, 10);
if (majorVersionIOS <= 13) {
console.log('YOu need some other regex');
} else {
console.log('YOu can use same regex');
}
Hope it helps. feel free for doubts
We ended up removing all the regexes from the app, and implemented them in the backend.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With