Lookbehind从一个字符串的结尾开始

Dud*_*ock 3 regex lookbehind

我确信之前一定要问过,但由于某些原因,在档案中找到正则表达式问题的答案对我来说特别困难.

我想从字符串的末尾开始做一个lookbehind.

示例字符串:

"This is a string with lots of white space_and-other.stuff"
Run Code Online (Sandbox Code Playgroud)

我只想要字符串中具有最后一个空格的部分.到目前为止,我有以下内容:

(?<=\s).+$
Run Code Online (Sandbox Code Playgroud)

这给了我第一个空格后的所有内容,即使我匹配字符串的结尾.我的问题根源必须与lookbehinds必须是预定义数量的字符有关,但我不知道怎么做没有lookbehind.

anu*_*ava 6

你为什么需要向后看.您可以使用此正则表达式获取它:

\S+$
Run Code Online (Sandbox Code Playgroud)