Reputation: 683
I need help to built regular expression for
string which does not start with pcm_ or PCM_
any guess!!!
Upvotes: 2
Views: 540
Reputation: 7438
see similar link
Regex pattern for checking if a string starts with a certain substring?
Upvotes: 1
Reputation: 3624
No need for a Regex here, simply use String.StartsWith http://msdn.microsoft.com/en-us/library/system.string.startswith.aspx
Upvotes: 0
Reputation: 645
As already pointed out, you don't need to use regular expressions for this, but if you wanted to you could use one with negative lookahead like so: ^(?!pcm_|PCM_).*$
Upvotes: 1
Reputation: 93036
The regex solution would be
^(?i)(?!pcm_)
(?i)
is the inline version of RegexOptions.IgnoreCase
^
matches the start of the string
(?!pcm_)
is a negative lookahead assertion, that is true if the string does not start with "pcm_" or "PCM_" (but also "PcM_, ...)
Upvotes: 1
Reputation: 3147
if (String.startsWith("pcm_") || String.startsWith("PCM_"))
{
//...
}
Upvotes: 2
Reputation: 94653
No need to use regular expression. Use String.startsWith() method.
if (!str.StartsWith("pcm_",StringComparison.InvariantCultureIgnoreCase)) {}
Upvotes: 5