close

(1) 如何找出 指定的tag 有用該屬性 的文字檔?
例題:「<rich:panel type="a" label="b">」。
答案:「(rich:panel[^>]*)\blabel(\s*=)」。  // 這是 tag 與 attribute 之間,有white-space也可以找出來的答案。
(1-2) 如何取代該屬性? (Eclipse)
例題:取代結果要為:「<rich:panel type="a" header="b">」。
答案:「$1header$2」。

來源:regex find and replace a specific attribute from a specific tag eclipse

 

(2) 如何移除 html上的 JavaScript?
[C#]

string htmlSource = Regex.Replace(htmlSource, @"<script[\d\D]*?>[\d\D]*?</script>", String.Empty);

(3) 如何移除 html tag?
[C#]

string htmlSource = Regex.Replace(htmlSource, @"<[^>]*>", String.Empty);

來源:[C#] Regex筆記- 移除所有HTML tag + 移除 JavaScript

 

(4) 檢查一字串中,是否至少包含:「一個大寫英文字母」、「一個小寫英文字母」、「一個數字」、「一個符號」
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$/
*不含前後「/」符號。
說明:

^                  // the start of the string
(?=.*[a-z])        // use positive look ahead to see if at least one lower case letter exists
(?=.*[A-Z])        // use positive look ahead to see if at least one upper case letter exists
(?=.*\d)           // use positive look ahead to see if at least one digit exists
(?=.*[_\W])        // use positive look ahead to see if at least one underscore or non-word character exists
.+                 // gobble up the entire string
$                  // the end of the string

出處:RegEx to make sure that the string contains at least one lower case char, upper case char, digit and symbol - Stack Overflow

(4-2) 加上長度檢查:
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).{8,10}+$/

參考:javascript - Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters - Stack Overflow

(4-3) 除了至少1個,加上限制 只能有列出的字元(不能含有以外字元(符號)):

/^(?=.*[a-z])(?=.*[A-Z])(?=.*[#%;@_`~])[a-zA-Z#%;@_`~]{9,20}$/

無價之寶

 

// 可陸續增加中..

= = = = = = =

線上工具:Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript

學習資料:正規表示式 Regular Expression | 就是愛程式
JWorld@TW Java論壇 - Java Regular Expression的學習筆記  

// 陸續增加中..

arrow
arrow
    文章標籤
    regex online tools learn
    全站熱搜

    Robert 發表在 痞客邦 留言(0) 人氣()