This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Filtering with a regular expression

0

I am trying to do a regex in wireshark on the following http header and want to filter the ones with an empty value.

User-Agent:

in the trace it shows User-Agent: \r\n

I tried a regex like the following to match User-Agent: followed by a space, then end of line.

frame matches "User-Agent:[\s]$"

but it doesnt work.

Can someone advise whats wrong? thanks

asked 26 Jun '13, 15:28

brumik's gravatar image

brumik
6223
accept rate: 0%


2 Answers:

2

I believe the "$" will anchor the regex to the end of the whole frame, not one particular line in the frame. Could you try:

frame matches "\\r\\nUser-Agent: \\r\\n"

answered 27 Jun '13, 09:20

SYN-bit's gravatar image

SYN-bit ♦♦
17.1k957245
accept rate: 20%

edited 27 Jun '13, 15:11

I assume you meant "matches" ? but yes it did work without the $ Also without the \r\n at the start. Thanks everyone for the help.

(27 Jun '13, 13:49) brumik

Yes I did, it's corrected :-)

Glad the filter works for you!

(27 Jun '13, 15:12) SYN-bit ♦♦

If a response answers your question, please mark it as the accepted answer for the benefit of others. Refer to the FAQ for more information.

(27 Jun '13, 20:02) cmaynard ♦♦

1

Please try this:

frame matches "User-Agent: \\r\\n$"

Regards
Kurt

answered 26 Jun '13, 16:35

Kurt%20Knochner's gravatar image

Kurt Knochner ♦
24.8k1039237
accept rate: 15%

thanks,

frame matches "User-Agent: \r\n$"

it still didnt match though.

However

http.user_agent == "" matches it but I wanted to use a regex.

(27 Jun '13, 00:25) brumik

Correction I meant:

frame matches "User-Agent: \r\n$"

still didnt do the trick

(27 Jun '13, 00:27) brumik

@brumik,

Your "answers" have been converted to comments as that's how this site works. Please read the FAQ for more information.

(27 Jun '13, 02:27) grahamb ♦

did you try 'double backslash'? Only that works in my test capture file.

frame matches "User-Agent: \\r\\n$"

instead of

frame matches "User-Agent: \r\n$"

(27 Jun '13, 05:50) Kurt Knochner ♦

Yes I did, strangely enough it didn't match with double backslash either.

(27 Jun '13, 08:53) brumik

it does for me. What is your Wireshark version?

(27 Jun '13, 13:16) Kurt Knochner ♦
showing 5 of 6 show 1 more comments