Matrix
Matrix

Reputation: 7623

does regular expression works when i translate them into another language?

For example: @"^\s*([a-zA-Z]*)\s*$", this is a regular expression,

Now i translated this expression into Chinese: @"^\小號*([一-ž一-ž]*)\小號*$"

Will it work (always)?

Upvotes: 3

Views: 114

Answers (2)

Cylian
Cylian

Reputation: 11181

Perhaps not, as every language has its own syntax and keywords, same it is applied for RegEx also.

May some RegEx flavors have some extra or less features compared to another (for example, PCRE flavor and .NET flavor, and an pattern (?<=\w+),. PCRE engine would fail to match the pattern, but the .NET engine would do.). But, how the core keywords and syntax could change?

Moreover, [a-z] would match only English-like letters ranges from code-point 97(dec) to 122(dec), and it would include code-point 65(dec) to 90(dec), if matching case-insensitive. If you use \p{L} (LETTER class), it would match any letters from any language.

Upvotes: 1

Tim Pietzcker
Tim Pietzcker

Reputation: 336448

I highly doubt it. Now I don't know Mandarin, Cantonese or any other "Chinese" language, so I can't tell what these "translations" actually mean. But I'm pretty sure you can't just go and transliterate the ASCII escape sequences into Chinese characters.

\s is a shorthand for whitespace. I'm betting \小號 isn't.

[A-Z] means "any character between A and Z. So [一-ž] might work if the Unicode code point value of is indeed below that of ž, and if those actually encompass the range of Chinese letters.

Upvotes: 2

Related Questions