6

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

  • First thing first I tried to update React Native to the latest version 0.61.5, but it didn't solve my issue
  • I've tried to replicate the same issue in a fresh new project and it didn't crash
  • Tried to remove all the regex, this worked, but the regex are part of a big and important functionality of the app

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

iPhone 6s simulator running iOS 11.2

Thanks for reading

fannolo
  • 357
  • 3
  • 10

2 Answers2

3

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

Gaurav Roy
  • 11,175
  • 3
  • 24
  • 45
  • Thank you for your answer! I was hoping to find a way to avoid substituting all the regex, what still concerns me is that the same regex is working perfectly fine on a fresh new project – fannolo Jan 08 '20 at 10:37
1

We ended up removing all the regexes from the app, and implemented them in the backend.

fannolo
  • 357
  • 3
  • 10