单词边界与点签到字符串
I'm trying to match different abbreviations for the german word "Straße" (e.g. "Str" or "Str.")
How can i escape the dot sign within the string?
\b(Str|Str.)\b
And how can i setup case-insensitive? It would be nice if the regex matches "str", "sTr", ... too.
我正在尝试匹配德语单词“Straße”的不同缩写(例如“Str”或“Str。 “) p>
如何在字符串中转义点符号? p>
\ b(Str | Str。)\ b
code> pre>
我如何设置不区分大小写? 如果正则表达式匹配“str”,“sTr”,......那就太好了。 p>
div>
You escape special characters with \
.
\b(Str|Str\.)\b
Also, ?
makes the preceding token optional, so we can condense to:
\b(Str\.?)\b
Finally, case insensitivity is specified with the i
modifier. How you specify modifiers depends on the language. In most cases they're put after the closing delimiter of the regex:
/\b(str\.?)\b/i
You can escape it by preceding it with a backslash. You can specify case insensitivity using an i
modifier.