Reputation: 10683
I'm trying to use Regex to get a bit if HTTP header parsing done. I'd like to use groups to organize some of the information:
Let's say I have this:
Content-Disposition: form-data; name="item1"
I'd like the result of my regex to create two groups:
contentdisposition : form-data
name : item1
I've tried several methods, but I can't seem to figure out how to do this. If name= doesn't exist then only one group should be created, but the regex should not error out.
Any ideas?
Upvotes: 2
Views: 4709
Reputation: 233
/Content-Disposition: (.*?);(?: name="(.*?)")?/
might be what you're looking for. It uses an optional greedy quantifier to get the name unless that would cause the match to fail.
Upvotes: 3