Regex match everything after question mark?

Regex match everything after question mark?

?(.*)

You want the content of the first capture group.

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:

(?<=?).*

Regex match everything after question mark?

With the positive lookbehind technique:

(?<=?).*

(Were 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.

Leave a Reply

Your email address will not be published.