Notepad++ RegEx replace with pattern

戏子无情 提交于 2020-01-30 13:28:32

问题


I want to find the following pattern:

Image not found: /Images/IMG-20160519-WA0015.jpg

And replace with some markup, including the image name from the above text like:

<a href="IMG-20160519-WA0015.jpg"><img src="IMG-20160519-WA0015.jpg" width="180" height="240" alt="IMG-20160519-WA0015.jpg" class="image" />

Is it possible with some kind of Regex or plugin or I'm simply burning neurones?

Thanks.


回答1:


Try finding ^Image not found: \/Images\/(IMG-.*\.jpg) and replacing with <a href="\1"><img src="\1" width="180" height="240" alt="\1" class="image" />

Note that the caret (^) in the regex says that it must be at the beginning of the line, not sure if that's the case for you but I suspect that it is. I also assumed that the "IMG-" prefix is constant, if not then you can just remove those four characters from the regex.

If you're not aware of it, RegExr is a nice interactive way to build and test regular expressions.

EDIT: Since you mentioned having trouble in the comments, here's an image of my settings:



来源:https://stackoverflow.com/questions/41942055/notepad-regex-replace-with-pattern

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!