2016-04-28 29 views
-4

Notepad ++(REGEX);反轉選擇,(REGEX);反轉選擇,

以下2個不同的代碼,它工作得非常好。 :) 現在我想結合這兩個不同的代碼!

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

https://codereview.stackexchange.com/questions/20126/regex-to-get-all-image-links

^((?!hello).)*$ 

notepad++ Inverse Regex replace (all but string)

+0

你的問題很糟糕,很難理解你想要什麼,以及到目前爲止你嘗試過了什麼? –

+0

看看http://stackoverflow.com/editing-help讓你的問題可讀。 –

回答

1

正向

確保您正在使用最新版本的記事本++,那裏有在記事本++ V5和其之前使用正則表達式已知問題已經在v6中更正。

說明

  • 捕捉該src屬性值
  • 作品用雙引號,單引號和非引用屬性值
  • 避免棘手邊緣情況通常絆倒簡單表達式

<img(?=\s|>)(?=(?:[^>=]|='[^']*'|="[^"]*"|=[^'"][^\s>]*)*?\ssrc=(['"]?)(.*?)\1(?:\s|>))(?:[^>=]|='[^']*'|="[^"]*"|=[^'"][^\s>]*)*>

enter image description here

如何

從記事本++

  1. CTRL˚F進入查找和替換 模式

  2. 選擇正則表達式選項

  3. 選擇「。匹配換行」選項

  4. 在 「查找內容」 字段的地方下面的正則表達式 <img(?=\s|>)(?=(?:[^>=]|='[^']*'|="[^"]*"|=[^'"][^\s>]*)*?\ssrc=(['"]?)(.*?)\1(?:\s|>))(?:[^>=]|='[^']*'|="[^"]*"|=[^'"][^\s>]*)*>

  5. 點擊查找全部

正則表達式實例

Live Demo

示例文字

注意前兩個圖像標籤有一些非常困難的邊緣情況

<img onmouseover=' img = 10; src="NotYourImage.png" ; if (3 <img && src="NotYourImage.png" && 6>3) { funRotate(src) ; } ; ' src="ImageYouAreLookingFor.png"> 
<img onmouseover=' src="NotTheDroidsYouAreLookingFor.png" ; if (x > 3) { funRotate(src); } ' src="http://another.example/picture.png"> 
<img src="./CaptchaServlet?rd=htb54m" class="flt" id="captcha" height="33" width="110"/> 

匹配

集團0獲取整個圖像標籤
1組獲取用於報價環繞src屬性,並用於確保正確的結尾報價匹配
組2獲取src值,或者如果您使用上面的替代正則表達式,將只接收第r個查詢字符串

[0][0] = <img onmouseover=' img = 10; src="NotYourImage.png" ; if (3 <img && src="NotYourImage.png" && 6>3) { funRotate(src) ; } ; ' src="ImageYouAreLookingFor.png"> 
[0][1] = " 
[0][2] = ImageYouAreLookingFor.png 

[1][0] = <img onmouseover=' src="NotTheDroidsYouAreLookingFor.png" ; if (x > 3) { funRotate(src); } ' src="http://another.example/picture.png"> 
[1][1] = " 
[1][2] = http://another.example/picture.png 

[2][0] = <img src="./CaptchaServlet?rd=htb54m" class="flt" id="captcha" height="33" width="110"/> 
[2][1] = " 
[2][2] = ./CaptchaServlet?rd=htb54m