正则表达式中匹配确切的单词

时间:2019-11-11 12:59:27

标签: regex

我正在尝试在最后一个点之前匹配一个确切的单词,在最后一个点之后应该是数字。

(\W*((?i)rocket\.jhagsc\.djagsh(?-i)(.*(?=\.).))\W*)((.*(?=\.).)(\d+))

示例:

rocket.jhagsc.djagsh.465465

它应该匹配。

1 个答案:

答案 0 :(得分:1)

我将其表达为:

\brocket.jhagsc.djagsh[^.]*\.(?!.*\.)\d.*$

以下是正则表达式模式的说明:

\brocket.jhagsc.djagsh   match your exact word
[^.]*                    then match zero or more non dots (i.e. allow no dots)
\.                       match the final dot
(?!.*\.)                 then assert that no more dots occur in the string
\d                       match a single digit immediately after the final dot
.*                       consume the remainder of the string
$                        end of the string

Demo