0

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
The fourth bird
  • 154,723
  • 16
  • 55
  • 70
Larry125
  • 25
  • 1
  • 4

1 Answers1

0

To catch all the content

:[^:]*:

To catch the content between

(?<=:)[^:]*(?=:)
  • 2
    Note that using a negated character class like that, it could also just match only newlines in between, where my assumption is that the OP wants to match at least a single none whitespace character or only word characters. See https://regex101.com/r/towFOb/1 – The fourth bird Nov 19 '22 at 13:29
  • 1
    You're right. It could be improved this way **(?<=:)[^:\r\n]*(?=:)** to avoid taking newlines. – Vincent Flotron Nov 19 '22 at 16:16
  • All of these suggestions helped - thank you very much! – Larry125 Nov 20 '22 at 16:11