2 回答
TA贡献1820条经验 获得超9个赞
头脑:
{0,1}
=?
{0,}
=*
{1,}
=+
使用
(\d+\.?\d*万?-?\d*\.?\d*万?)元?/(?!套)
查看证明
解释
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
\.? '.' (optional (matching the most amount
possible))
--------------------------------------------------------------------------------
\d* digits (0-9) (0 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
万 '万'
--------------------------------------------------------------------------------
;? ';' (optional (matching the most amount
possible))
--------------------------------------------------------------------------------
-? '-' (optional (matching the most amount
possible))
--------------------------------------------------------------------------------
\d* digits (0-9) (0 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
\.? '.' (optional (matching the most amount
possible))
--------------------------------------------------------------------------------
\d* digits (0-9) (0 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
万 '万'
--------------------------------------------------------------------------------
;? ';' (optional (matching the most amount
possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
元 '元'
--------------------------------------------------------------------------------
;? ';' (optional (matching the most amount
possible))
--------------------------------------------------------------------------------
/ '/'
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
套 '套'
--------------------------------------------------------------------------------
) end of look-ahead
TA贡献1815条经验 获得超6个赞
如果我理解正确的话,使用向前看和向后看这相当简单......
(?<=:)(\d+)(?!.*套) : Using positive look behind to make sure the number is preceded by a colon, doesn't include the colon in the "full match"
:(\d+)(?!.*套) : Not using positive look behind; colon is included in "full match" but not in groups
(?<=:)(\d+)(?!.*套)
(?<= : Start of positive look behind
: : String to search for
) : End of positive look behind
( : Start of capture group
\d+ : Capture any number 1 or more times
) : End of capture group
(?! : Start of negative look ahead
.* : Greedy "capture anything" before string we're trying to avoid
套 : String we're trying to avoid
) : End of negative look ahead
添加回答
举报