How to make Regex choose words separately

后端 未结 2 1658
醉话见心
醉话见心 2021-01-25 06:49

So I have this string:

sockcooker!~shaz@Rizon-AC7BDF2F.dynamic.dsl.as9105.com !~shaz@ PRIVMSG #Rizon :ohai. New here. registered 10 mins ago, have not got an ema         


        
2条回答
  •  面向向阳花
    2021-01-25 07:32

    You want to use an ungreedy match. There are two ways (and python supports both). The latter is more flexible:

    r"![^@]+"
    r"!.+?@
    

    The ? makes the .+ ungreedy, so it will stop at the first "@" instead of the last.

提交回复
热议问题