0cool
0cool

Reputation: 683

Regular expression for matching start of string with

I need help to built regular expression for

string which does not start with pcm_ or PCM_

any guess!!!

Upvotes: 2

Views: 540

Answers (6)

Guillaume Slashy
Guillaume Slashy

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

jfiskvik
jfiskvik

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

stema
stema

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

gabsferreira
gabsferreira

Reputation: 3147

if (String.startsWith("pcm_") || String.startsWith("PCM_"))
{
    //...
}

Upvotes: 2

KV Prajapati
KV Prajapati

Reputation: 94653

No need to use regular expression. Use String.startsWith() method.

if (!str.StartsWith("pcm_",StringComparison.InvariantCultureIgnoreCase)) {}

Upvotes: 5

Related Questions