I'm trying to decode the following regex expression. For some reason, it doesn't work on my online decoder. Can anybody help me decrypt the following:
Regex r = new Regex("src=\"(?<src>[^\"]+)\"")
Thanks.
I'm trying to decode the following regex expression. For some reason, it doesn't work on my online decoder. Can anybody help me decrypt the following:
Regex r = new Regex("src=\"(?<src>[^\"]+)\"")
Thanks.
It seems that you're missing the last quotation symbol, but let's ignore that.
Autopsy:
src=\"(?<src>[^\"]+)\"
src= - The literal string src=\" - A literal quote (escaped to make sure the string doesn't terminate)(?<src>[^\"]+)
src (?<src>) matching:[^\"]+ - Any character that isn't a " character, matched 1 to infinity times (+)\" - A literal quote (escaped to make sure the string doesn't terminate)
In human words:
With the string <img src="picture.png" /> this will create a named capturing group named src containing picture.png.
Regex limitations:
If your image is created using single quotes (<img src='picture.png' />) this will not work correctly. In that case you can use something like:
src=(\"(?<src1>[^\"]+)\"|\'(?<src2>[^\']+)\')
^
DOUBLE QUOTES OR SINGLE QUOTES
that will match both (in either src1 or src2 depending on the quotation type).

Perhaps because your pattern was incorrect to begin with? I think this is what you wanted:
Regex r = new Regex("src=\"([^\"]+)\"")
This will capture image.jpeg in src="image.jpeg".