Can regular expressions work with different languages?

后端 未结 8 1480
慢半拍i
慢半拍i 2020-12-10 05:42

English, of course, is a no-brainer for regex because that\'s what it was originally developed in/for:

Can regular expressions understand this charact

相关标签:
8条回答
  • 2020-12-10 06:14

    As far as I know, there isn't any specific pattern you can use i.e. [a-zA-Z] to match "è", but you can always match them in separately, i.e. [a-zA-Zè正]

    Obviously that can make your regexp immense, but you can always control this by adding your strings into variables, and only passing the variables into the expressions.

    0 讨论(0)
  • 2020-12-10 06:15

    "[\p{L}]" This regular expression contains all characters that are letters, from all languages, upper and lower case. so letters like (a-z A-Z ä ß è 正 の文字を理解) are accepted but signs like (, . ? > :) or other similar ones are not.

    • the brackets [] mean that this expression is a set.
    • If you want unlimited number of letters from this set to be accepted, use an astrix * after the brackets, like this: "[\p{L}]*"
    • it is always important to make sure you take care of white space in your regex. since your evaluation might fail because of white space.
    0 讨论(0)
提交回复
热议问题