tags:

views:

26

answers:

2

Using System.Text.RegularExpressions with the following expression to match all tokens wrapped with # that contain only text (no whitespace etc)

#([a-zA-Z]+)#

and the following test string

text #test# text #test1# text

I only get one match. What am I doing wrong in my regex?

A: 

It will match the first item only

use NextMatch() function

Pramodh
+1  A: 

You can use the Matches() method, which returns a collection of all matches.

Also, A-Z is not really a good solution for text (and indeed the 1 in #test1# will not be matched!!!), since it doesn't include any extended character, such as éàèöäü etc. - you may want to look at \w which matches word characters, or \p{L} to match any letter in any language.

Edit: maybe this would suit your needs better:

#([^\s#]+)#
Lucero