Reputation: 1864
I'm quite new with regex. (.net)
I need a regular expression which selects anything from /* to */
(including /* and */).
My Problem - is that i'm not able to get the right expressen with these special characters.
With standard strings it works fine.
Once more... it should select over linebreaks.
i.e.:
text
/*
some text
*/
text
the result should be:
/*
some text
*/
Can someone please help me?
Thanks a lot!
Upvotes: 0
Views: 66
Reputation: 2927
this should work: Regex.Match("/*hello*/", "^(/\*(.*?)\*/)$", RegexOptions.SingleLine)
Upvotes: 2
Reputation: 2551
You need to escape the *
: /\*.*?\*/
And use the Singleline
option so the .
(dot) matches break lines.
You can access the matched content like this :
string value;
string pattern = @"/\*.*?\*/"
Match match = Regex.Match(input, pattern, RegexOptions.Singleline);
if( match.Success )
{
value = match.Value;
}
Upvotes: 1