Search code examples
pythonregexnlp

Python Regex to match a colon either side (left and right) of a word


At a complete loss here - trying to match a a colon either side of any given word in a passage of text.

For example:

:wave: Hello guys! :partyface: another huge win for us all to celebrate!

An appropriate regex that would match:

:wave:
:partyface:

Really appreciate your help!

\w*:\b

Solution

  • To catch all the content

    :[^:]*:
    

    To catch the content between

    (?<=:)[^:]*(?=:)