I've used regex in the past for input validation, but I am wondering if they can let you parse a complex string.
I have a header like this:
-----------------------------7dac1d2214d4\r\nContent-Disposition: form-data; name=\"my_title\"\r\n\r\nMyData\r\n-----------------------------7dac1d2214d4\r\nContent-Disposition: form-data; name=\"myupload\"; filename=\"C:\\myfile.zip\"\r\nContent-Type: application/x-zip-compressed\r\n\r\n
I want to be able to parse out say, the filename.
At the moment I am doing this (after parsing headers):
this.FileName = headers[1].Substring(headers[1].IndexOf("filename=\"") + "filename=\"".Length, headers[1].IndexOf("\"\r\n", headers[1].IndexOf("filename=\"")) - (headers[1].IndexOf("filename=\"") + "filename=\"".Length));
But it's hideous and ugly.
Can regex solve this problem more elegently? I understand the basics of the syntax, so if it can solve it, could someone show me how to parse this with regex:
"+Name=Bob+Age=39+"
I can probably work out the rest myself then.
Thanks.