Search code examples
c#asp.netregexqregexp

Regex to find word starting and ending with ##


I am using ##\b\S+?\b## regex to find word starting and ending with ## which finds the below,

##YourFriend##

This does not work when there is a space in between words like

##Your Friend##

I need a regex which works for both the cases, that could find both,

 ##YourFriend##
 ##Your Friend##

I tried using \s which is used to find the white spaces, but it does not work.


Solution

  • You can use this: ##.*?##.

    Which will match the two ##s in a non greedy way.