正则表达匹配 东欧语言特殊字符
地址: https://www.thinbug.com/q/1922097
我一直在使用的字符类如下:
[\wÀ-Üà-øoù-ÿŒœ]。它所覆盖的字符集仅比法语略大,但不包括东欧和斯堪的纳维亚的变音符号和与法语无关的字母。我发现这是简洁与排他性之间的不错折衷。
要匹配/验证完整句子,我使用以下表达式: [\w\s.,!?:;&#%’'"()«»À-Üà-øoù-ÿŒœ],其中包括标点符号和法式引号。
"()" can be used to form sub-patterns. The quantity operators listed above operate on the shortest previous pattern, which can be a group. For string "ababab":(ab)+ # match
ab(ab)+ # match
(..)+ # match
(...)+ # no match
(ab)* # match
abab(ab)? # match
ab(ab)? # no match
(ab){3} # match
(ab){1,2} # no match
"|" acts as an OR operator. The match will succeed if the pattern on either the left-hand side OR the right-hand side matches. The alternation applies to the longest pattern, not the shortest. For string "aabb":aabb|bbaa # match aacc|bb # no match aa(cc|bb) # match a+|b+ # no match a+b+|b+a+ # match a+(b|c)+ # match
"[]". A leading ^ negates the character class. The allowed forms are:[abc] # 'a' or 'b' or 'c' [a-c] # 'a' or 'b' or 'c' [-abc] # '-' or 'a' or 'b' or 'c' [abc\-] # '-' or 'a' or 'b' or 'c' [^abc] # any character except 'a' or 'b' or 'c' [^a-c] # any character except 'a' or 'b' or 'c' [^-abc] # any character except '-' or 'a' or 'b' or 'c' [^abc\-] # any character except '-' or 'a' or 'b' or 'c'
"-" indicates a range of characters, unless it is the first character or if it is escaped with a backslash."abcd":ab[cd]+ # match [a-d]+ # match [^a-d]+ # no match