tags:

views:

15

answers:

2

I'm building a dynamic code generator and using regular expressions. Given this block of text

##Properties
                            public #PropertyType# #NewProperty#
                            {
                                get; set;
                            }
##
##Events
                            public event #EventName#-#EventExt#;
##
                            }
                            #endregion

I want to be able to extract to blocks of text, namely:

##Properties
                            public #PropertyType# #NewProperty#
                            {
                                get; set;
                            }
##

and

##Properties
                            public #PropertyType# #NewProperty#
                            {
                                get; set;
                            }
##

I've been trying to use this ##[\S\s]+## as my expression but it's taking both and joining them into one. So I was wondering if there was a way to exclude the "##" characters from the [\S\s] class so that it doesn't get recognized. Is there such a way to do this?

+2  A: 

Try using lazy on your regular expression:

##[\S\s]+?##

This will match as few characters as possible.

elusive
+1  A: 

Try

##(?:[^#]|#(?!#))+##
KennyTM