开发者

Regex Problem: name capture, preg_match

开发者 https://www.devze.com 2023-03-31 17:31 出处:网络
Given the following strings: application/pdf; name=a.pdf application/pdf; name=\"b.pdf\" application/pdf; name=\"c.pdf

Given the following strings:

application/pdf; name=a.pdf
application/pdf; name="b.pdf"
application/pdf; name="c.pdf
application/pdf; name=d.pdf"

I need the following values in a capture named "filename":

a.pdf
b.pdf
c.pdf
d.pdf

The following regex works for a.pdf, but fails for the rest due to the dou开发者_C百科ble quotes:

name=(?<filename>.*)

Any suggestions how I can get the rest? Thanks.


Try this one:

/name="?(?<filename>[^"]*)"?/
0

精彩评论

暂无评论...
验证码 换一张
取 消