正则表达式来一个特定的词后,立即查找的单词单词、正则表达式

2023-09-05 04:09:42 作者:落雪无声

我想用一个正则表达式字符串中一个特定的词后,立刻找到这个词。例如,如果单词是我的',

I want to find the word immediately after a particular word in a string using a regex. For example, if the word is 'my',

这是我的祈祷 - 祈祷

"This is my prayer"- prayer

这是我的书() - 书

"this is my book()"- book

是否有可能使用正则表达式?

Is it possible using regex?

推荐答案

正则表达式是

(?<=\bmy\s+)\p{L}+

\ p {L〕+ 是一个字母序列。该 \ p {L〕是统一code code与物业点,因此在任何语言的信相匹配。

\p{L}+ is a sequence of letters. The \p{L} is a Unicode code point with the property "Letter", so it matches a letter in any language.

(小于?= \ BMY \ S +)是向后断言,确保之前

(?<=\bmy\s+) is a lookbehind assertion, that ensures thet word "my" is before