Regex在问号之后匹配所有内容?

时间:2021-05-18 22:24:42

I have a feed in Yahoo Pipes and want to match everything after a question mark.

我在雅虎管道中有一个feed,想要在一个问号后面匹配所有东西。

So far I've figured out how to match the question mark using..

到目前为止,我已经学会了如何用…

\?

Now just to match everything that is after/follows the question mark.

现在来匹配问号后面的所有内容。

5 个解决方案

#1


161  

\?(.*)

You want the content of the first capture group.

您需要第一个捕获组的内容。

#2


32  

Try this:

试试这个:

\?(.*)

The parentheses are a capturing group that you can use to extract the part of the string you are interested in.

圆括号是一个捕获组,您可以使用它提取感兴趣的字符串的一部分。

If the string can contain new lines you may have to use the "dot all" modifier to allow the dot to match the new line character. Whether or not you have to do this, and how to do this, depends on the language you are using. It appears that you forgot to mention the programming language you are using in your question.

如果字符串可以包含新的行,您可能需要使用“点所有”修饰符来允许点匹配新的行字符。你是否必须这样做,以及如何这样做,取决于你使用的语言。您似乎忘记了在您的问题中使用的编程语言。

Another alternative that you can use if your language supports fixed width lookbehind assertions is:

如果您的语言支持固定宽度的查找断言,您可以使用的另一个替代方法是:

(?<=\?).*

#3


10  

With the positive lookbehind technique:

使用积极的后视镜技术:

(?<=\?).*

(? < = \ ?)。*

(We're searching for a text preceded by a question mark here)

(我们搜索的文本前面有问号)

Input: derpderp?mystring blahbeh
Output: mystring blahbeh

Example

例子

Basically the ?<= is a group construct, that requires the escaped question-mark, before any match can be made.

基本上?<=是一个组结构,它需要转义的问号才能进行匹配。

They perform really well, but not all implementations support them.

它们的性能非常好,但并不是所有的实现都支持它们。

#4


8  

\?(.*)$

If you want to match all chars after "?" you can use a group to match any char, and you'd better use the "$" sign to indicate the end of line.

如果您想匹配“?”之后的所有字符,您可以使用组来匹配任何字符,最好使用“$”符号来指示行尾。

#5


2  

Check out this site: http://rubular.com/ Basically the site allows you to enter some example text (what you would be looking for on your site) and then as you build the regular expression it will highlight what is being matched in real time.

查看这个站点:http://rubular.com/基本上这个站点允许您输入一些示例文本(您将在站点上查找的内容),然后在构建正则表达式时,它将突出显示实时匹配的内容。

#1


161  

\?(.*)

You want the content of the first capture group.

您需要第一个捕获组的内容。

#2


32  

Try this:

试试这个:

\?(.*)

The parentheses are a capturing group that you can use to extract the part of the string you are interested in.

圆括号是一个捕获组,您可以使用它提取感兴趣的字符串的一部分。

If the string can contain new lines you may have to use the "dot all" modifier to allow the dot to match the new line character. Whether or not you have to do this, and how to do this, depends on the language you are using. It appears that you forgot to mention the programming language you are using in your question.

如果字符串可以包含新的行,您可能需要使用“点所有”修饰符来允许点匹配新的行字符。你是否必须这样做,以及如何这样做,取决于你使用的语言。您似乎忘记了在您的问题中使用的编程语言。

Another alternative that you can use if your language supports fixed width lookbehind assertions is:

如果您的语言支持固定宽度的查找断言,您可以使用的另一个替代方法是:

(?<=\?).*

#3


10  

With the positive lookbehind technique:

使用积极的后视镜技术:

(?<=\?).*

(? < = \ ?)。*

(We're searching for a text preceded by a question mark here)

(我们搜索的文本前面有问号)

Input: derpderp?mystring blahbeh
Output: mystring blahbeh

Example

例子

Basically the ?<= is a group construct, that requires the escaped question-mark, before any match can be made.

基本上?<=是一个组结构,它需要转义的问号才能进行匹配。

They perform really well, but not all implementations support them.

它们的性能非常好,但并不是所有的实现都支持它们。

#4


8  

\?(.*)$

If you want to match all chars after "?" you can use a group to match any char, and you'd better use the "$" sign to indicate the end of line.

如果您想匹配“?”之后的所有字符,您可以使用组来匹配任何字符,最好使用“$”符号来指示行尾。

#5


2  

Check out this site: http://rubular.com/ Basically the site allows you to enter some example text (what you would be looking for on your site) and then as you build the regular expression it will highlight what is being matched in real time.

查看这个站点:http://rubular.com/基本上这个站点允许您输入一些示例文本(您将在站点上查找的内容),然后在构建正则表达式时,它将突出显示实时匹配的内容。