Unicode Properties are not supported/broken for Regular Expressions (Regex)
See original GitHub issueDescription
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.
- 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;
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:6 (1 by maintainers)
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