我想匹配任何长度超过 2 个字母的非 ASCII 单词,并在其周围添加括号。例如此字符串
[i]Abandon one's post:[/i] [c]P.[/c] τάξιν ο οὕνεχ’ ὅρκων, ἀν λείπειν, [c]V.[/c] τάξιν το ἐρημοῦν.
应该成为
[i]Abandon one's post:[/i] [c]P.[/c] [[τάξιν]] ο [[οὕνεχ]]’ [[ὅρκων]], ἀν [[λείπειν]], [c]V.[/c] [[τάξιν]] το [[ἐρημοῦν]].
我尝试过这个,但是没有匹配任何内容
(?i)\b[a-z]*(?![a-z])\pM*\pL\w*
https://stackoverflow.com/questions/33967954/regex-to-search-for-words-containing-foreign-characters
答案1
据我所知,Npp 不知道 mark 属性\pM
,但你可以这样做:
- Ctrl+H
- 找什么:
\b((?:(?![a-zA-Z])\pL){3,})\b
- 用。。。来代替:
[[$1]]
- Replace all
解释:
\b : word boundary
( : start group 1
(?: : start non capture group
(?! : lookahead, make sure next character is NOT
[a-zA-Z] : latin letter
) : end lookahead
\pL : any letter in any language, case insensitive
){3,} : must appear at least three times
) : end group 1
\b : word boundary
替代品:
[[$1]] : content of group 1 surrounded with brackets
给定示例的结果:
[i]Abandon one's post:[/i] [c]P.[/c] [[τάξιν]] ο [[οὕνεχ]]’ [[ὅρκων]], ἀν [[λείπειν]], [c]V.[/c] [[τάξιν]] το [[ἐρημοῦν]].