正则表达式将所有字符都放在第一个空格的右边? [英] Regex to get all character to the right of first space?
本文介绍了正则表达式将所有字符都放在第一个空格的右边?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作一个正则表达式,该表达式将匹配(但不包括)字符串中第一个空格之后的所有字符.
I am trying to craft a regular expression that will match all characters after (but not including) the first space in a string.
输入文本:
foo bar bacon
想要的匹配:
bar bacon
到目前为止我发现的最接近的是:
The closest thing I've found so far is:
\s(.*)
然而,这匹配除了bar bacon"之外的第一个空格,这是不可取的.任何帮助表示赞赏.
However, this matches the first space in addition to "bar bacon", which is undesirable. Any help is appreciated.
推荐答案
您可以使用 positive lookbehind:
(?<=\s).*
(演示)
虽然看起来您已经在当前正则表达式中的 .*
周围放置了一个捕获组,因此您可以尝试抓取它.
Although it looks like you've already put a capturing group around .*
in your current regex, so you could just try grabbing that.
这篇关于正则表达式将所有字符都放在第一个空格的右边?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文