Regular expressions: Difference between revisions

Content added Content deleted
No edit summary
m (→‎{{header|C#}}: removed unnecessary characters)
Line 64: Line 64:
=={{header|C#}}==
=={{header|C#}}==
{{works with|.NET|2.0+}}
{{works with|.NET|2.0+}}
Import System.Text.RegularExpressions;
Test
string str = "I am a clever string";
Import System.Text.RegularExpressions;
string pattern = ".*clever.*";

Regex regex = new Regex(pattern);
string str = "I am a clever string";
if ( regex.IsMatch( str) ) {
string pattern = ".*clever.*";
Console.WriteLine( "The string contains clever" );
Regex regex = new Regex(pattern);
}
if ( regex.IsMatch( str) ) {
if ( Regex.IsMatch( str, pattern ) ) {
Console.WriteLine( "The string contains clever" );
Console.WriteLine( "A more clever way to detect that the string contains clever" );
}
}
if ( Regex.IsMatch( str, pattern ) ) {
Console.WriteLine( "A more clever way to detect that the string contains clever" );
}



=={{header|D}}==
=={{header|D}}==