user611105
user611105

Reputation:

Regex to grab strings with a space at the end

I am trying to extract some data from URLs in a LOG file and I'm almost there but the last part I am stuck on.

Here is the regex I have come up with so far,

(\?.*\s+)

Example of URLs I am working with

json?userId=1234&[email protected] HTTP/1.1

And I want to pull out

userId=1234&[email protected]

Across multiple lines of similar URL lines. The regex above gets the right stuff at the start but does not stop after the whitespace. What am I missing to make it not include the ? and end at the white space properly?

Edit: Clarified question a bit.

Upvotes: 0

Views: 76

Answers (2)

Ben
Ben

Reputation: 673

This works in sed.

echo "json?userId=1234&[email protected] HTTP/1.1" | sed 's/.*?\(.*\)\s.*$/\1/

you might also try. (\?[^\s]+) match as many not space characters after a ?

Upvotes: 0

Philipp
Philipp

Reputation: 1445

I used to do it that way:

\?([^ ]*) -> \1

I do not know your implementation, but it's "working" on http://regexpal.com/ (this tester does not replace)

Edit: forgot the "?"

Upvotes: 1

Related Questions