Reputation: 751
I'm trying to build a regex to match English with special characters and also the emojis, I found this one [\u0000-\u007F]+$
for English with special characters and this one ([^\x00-\x7F]+\ *(?:[^\x00-\x7F]| )*)
for emojis but I can't figure how to combine both, any idea how?.
Upvotes: 3
Views: 1766
Reputation: 18641
If you need to match any string that cannot contain any non-English letter use
^(?:[a-zA-Z]|\P{L})+$
Code sample:
RegExp regex = RegExp(r'^(?:[a-zA-Z]|\P{L})+$', unicode: true);
See proof
Explanation
EXPLANATION
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
(?: group, but do not capture (1 or more times
(matching the most amount possible)):
--------------------------------------------------------------------------------
[a-zA-Z] any character of: 'a' to 'z', 'A' to 'Z'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
\P{L} any char other than a Unicode letter
--------------------------------------------------------------------------------
)+ end of grouping
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
string
Upvotes: 5