Capturing a string to a character, but not containing a character

With string http://stackoverflow.com/questions/ask?hello=world

you can use /^.+\?/

to capture http://stackoverflow.com/questions/ask?

. How can I just grab http://stackoverflow.com/questions/ask

.

+1


source to share


3 answers


you can use ^[^?]+

This will be displayed until a question mark is found, but a question mark is not received.



Check it out .

+1


source


Include the part of the regex that matches the parenthesized string you want and use groups to get it.

 /(^.+)\?/

      



Group 1 will contain all but the final string matched ?

.

+1


source


use this regexrpession /^.+(?=\?)/

+1


source







All Articles