Regex match everything after question mark?

Regex

Regex Problem Overview


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

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.

Regex Solutions


Solution 1 - Regex

\?(.*)

You want the content of the first capture group.

Solution 2 - Regex

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:

(?<=\?).*

Solution 3 - Regex

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.

Solution 4 - Regex

\?(.*)$

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.

Solution 5 - Regex

?(.*\n)+

With this you can get everything Even a new line

Solution 6 - Regex

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.

Solution 7 - Regex

str.replace(/^.+?\"|^.|\".+/, '');

This is sometimes bad to use when you wanna select what else to remove between "" and you cannot use it more than twice in one string. All it does is select whatever is not in between "" and replace it with nothing.

Even for me it is a bit confusing, but ill try to explain it. ^.+? (not anything OPTIONAL) till first " then | Or/stop (still researching what it really means) till/at ^. has selected nothing until before the 2nd " using (| stop/at). And select all that comes after with .+.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarkView Question on Stackoverflow
Solution 1 - RegexthejhView Answer on Stackoverflow
Solution 2 - RegexMark ByersView Answer on Stackoverflow
Solution 3 - RegexDarkNeuronView Answer on Stackoverflow
Solution 4 - Regexs3v3nView Answer on Stackoverflow
Solution 5 - RegexHossein MohammadiView Answer on Stackoverflow
Solution 6 - RegexAustin LinView Answer on Stackoverflow
Solution 7 - RegexKadhemView Answer on Stackoverflow