質問

1) var chk = $(this).attr('src'); if (chk = "Images/1.png")

2) .attr('chk', 'Images/1.png');

3) if ($(this).attr('src') == 'Images/1.png')

I can have above 3 syntax to set images in java script. Is there any Regex to get Images/1.png from above 3 syntax. If there is 3 regex for all above 3 syntaxes, It will be fine, but 1 Regex, if posible, will be great.

役に立ちましたか?

解決 2

Regex to get all image references in .aspx, .js, .css, .cshtml, .html, .ascx is

"(?=\w)([\w\/]+(?:.png|.jpg|.jpeg|.gif))|([.\~\-\:\w\/]+(?:.png|.jpg|.jpeg‌​|.gif))"

Thanks a lot Aelor for your help.

他のヒント

[^\s\'\"]+\/[^\s\'\"]+

this will get you the desired result, it will find all the links (correct/incorrect format) in the sentence and give you .

Suppose you want only particular links with particular format

([^\s\'\"]+\/[^\s\'\"]+(?:png|jpg|jpeg))

this will give only those ending with png, jpg or jpeg

demo here : http://regex101.com/r/nL4vJ0

update

according to the comment of OP, I am posting a new regex which will be working in all his test cases.

(?=\w)([\w\/]+(?:\.png|\.jpg|\.jpeg))

demo here : http://regex101.com/r/wG5hX7

final update

(?=\w)([\w\/]+(?:\.png|\.jpg|\.jpeg|\.gif))|([\.\~\-\w\/]+(?:\.png|\.jpg|\.jpeg‌​|\.gif))

final updated regex which supports all your conditions

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top