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 .
http://stackoverflow.com/questions/ask?hello=world
/^.+\?/
http://stackoverflow.com/questions/ask?
http://stackoverflow.com/questions/ask
you can use ^[^?]+
^[^?]+
This will be displayed until a question mark is found, but a question mark is not received.
Check it out .
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 ? .
?
use this regexrpession /^.+(?=\?)/
/^.+(?=\?)/