Regular expression to match a dot

后端 未结 6 560
无人共我
无人共我 2020-11-22 09:51

Was wondering what the best way is to match \"test.this\" from \"blah blah blah test.this@gmail.com blah blah\" is? Using Python.

I\'ve tri

6条回答
  •  无人共我
    2020-11-22 10:36

    "In the default mode, Dot (.) matches any character except a newline. If the DOTALL flag has been specified, this matches any character including a newline." (python Doc)

    So, if you want to evaluate dot literaly, I think you should put it in square brackets:

    >>> p = re.compile(r'\b(\w+[.]\w+)')
    >>> resp = p.search("blah blah blah test.this@gmail.com blah blah")
    >>> resp.group()
    'test.this'
    

提交回复
热议问题