Reputation: 75
I've tried to make a regex expression to match a piece of code, but no success. The expression doesn't work in vs2008.
I've created this one:
/\*<parameters>\*/(?<value>[\r\n]*.*)/\*</parameters>\*/
the source to match is:
/*<parameters>*/
@parameter blue
,@parameter2 red
,@parameter3 green
,@parameter4 yellow /*</parameters>*/
Or better:
/*<parameters>*/ \r\n @parameter blue \r\n ,@parameter2 red \r\n ,@parameter3 green \r\n ,@parameter4 yellow /*</parameters>*/
Can anybody help me?
thanks, Rodrigo Lobo
Upvotes: 2
Views: 208
Reputation: 75222
As Alex said, you can use the Singleline modifier to let the dot match newline characters (\r and \n). You can also use the inline form - (?s)
- to specify it within the regex itself:
(?s)/*<parameters>*/(?<value>.*?)/*</parameters>*/Also notice the reluctant quantifier: "
.*?
". That's in case there's more than one potential match in the text; otherwise you would match from the first <parameters>
tag to the last </parameters>
tag.
Upvotes: 0
Reputation: 30934
The following will do the trick:
/\*<parameters>\*/(.|\r|\n)*/\*</parameters>\*/
Alternatively, if you want to exclude the outer tokens from the match itself:
(?<=/\*<parameters>\*/)(.|\r|\n)*(?=/\*</parameters>\*/)
Upvotes: 1
Reputation: 1159
Try this Regex out: /\*<parameters>\*/(?<value>[^/]*)/\*</parameters>\*/
A good tool for fooling around with real c# Regex patterns is regex-freetool on code.google.com
Upvotes: 4
Reputation: 8911
I don't want to give you fish for this question, so you may want to try out this free tool (with registration) from Ultrapico called Expresso.
I have stumbled with Regex for several time, and Expresso saved the day on all occassion.
Upvotes: -1
Reputation: 881635
RegexOptions.Multiline
only changes the semantics of ^
and $
-- you need RegexOptions.Singleline
to let .
match line-ends as well (a confusion I've been caught in myself;-).
Upvotes: 2
Reputation: 12796
Your regex should match the all the text you specified, after you turn on the regex "Multiline" option.
Upvotes: 0