question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unicode Properties are not supported/broken for Regular Expressions (Regex)

See original GitHub issue

Description

The Unicode Properties feature for regular expression is supported for Node, Swift and Java (see References bellow). However, when I use that feature in my code, it returns a wrong answer (specifically I used \p{L} and the test method). For example, /\p{L}/u.test('a') returns false.

References

JS - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Unicode_Property_Escapes Swift - https://developer.apple.com/documentation/foundation/nsregularexpression Java - https://docs.oracle.com/javase/tutorial/essential/regex/unicode.html

React Native version:

System:
    OS: Windows 10 10.0.19041
    CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
    Memory: 3.49 GB / 15.90 GB
  Binaries:
    Node: 14.5.0 - C:\Program Files\nodejs\node.EXE     
    Yarn: Not Found
    npm: 6.14.6 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.1
      System Images: android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: Version  4.0.0.0 AI-193.6911.18.40.6626763
  Languages:
    Java: 1.8.0_211
    Python: 2.7.18
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: 0.63.2 => 0.63.2
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. run the code
console.log(/\p{L}/u.test('a'));
console.log(/\p{L}/u.test('ש'));

anywhere in your app component.

Expected Results

/\p{L}/u.test('a') and /\p{L}/u.test('ש') should return true (they have the unicode property “Letter”). they both return false.

Snack, code example, screenshot, or link to a repository:

import React from 'react';
import { View, Text } from 'react-native';

function App() {
  console.log(/\p{L}/u.test('a'));
  console.log(/\p{L}/u.test('ש'));
  return (
    <View>
      <Text>App</Text>
    </View>
  );
}

export default App;

image

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
conradlocommented, Dec 17, 2020

I had the same issue recently. Out team’s solution is to use the @babel/plugin-proposal-unicode-property-regex plugin to transpile the unicode regex.

2reactions
arnaudambrocommented, May 26, 2021

I had the same issue recently. Out team’s solution is to use the @babel/plugin-proposal-unicode-property-regex plugin to transpile the unicode regex.

it doesn’t do anything for me, is there an extra step to do ?

[EDIT]

I forgot to update my babel config in babel.config.js

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: ['@babel/plugin-proposal-unicode-property-regex'],
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Regex Tutorial - Unicode Characters and Properties
Unicode Regular Expressions. Unicode is a character set that aims to define all characters and glyphs from all human languages, living and dead....
Read more >
UTS #18: Unicode Regular Expressions
Unicode is a large character set—regular expression engines that are only adapted to handle small character sets will not scale well.
Read more >
Unicode properties and regular expressions - NUMA
Unicode properties for regular expressions. Regular expressions standardization or ... Of course not all properties apply to all characters.
Read more >
Unicode property escapes - JavaScript - MDN Web Docs
The Script and Script_Extensions Unicode properties allow regular expression to match characters according to the script they are mainly ...
Read more >
How can I use Unicode-aware regular expressions in ...
As mentioned in other answers, JavaScript regexes have no support for Unicode character classes. However, there is a library ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found