[英]Perl Regex to Match Colon Occurrence if Present
如果第一個單詞包含“Blue”,我想正則表達式匹配字符串中的任何字母/數字/下划線字符以及雙冒號。
例如,
Blue Red Yellow //return Red
Blue Red::Orange Yellow //return Red::Orange
Purple Red Yellow //return nothing
Blue R_E_D //return R_E_D
Red Blue //return nothing
Blue.ish Yellow //return Yellow
我試過/Blu\S+\s+(\w+)/
它適用於除::
案例之外的所有案例。 如何在檢查w+
以匹配雙冒號以及如果存在時添加匹配項,而不必強制我的正則表達式僅在存在::
時才匹配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.