Simple reg exp

I need a simple reg exp that checks for “dab” as the first 3 characters of a string

cheers

I still fail to see why you need regex.


// javascript

"some string".toLowerCase().indexOf("dab", 0) == 0; // false
"DaB blah blah blah".toLowerCase().indexOf("dab", 0) == 0; // true
"aDaB blah blah blah".toLowerCase().indexOf("dab", 0) == 0; // false

then take what I had and whatever .NET uses for case insensitivity (most languages use “i” at the end of the pattern) and that ought to do it.

^ means “begins with”
dab are literally-matched letters

  • means anything or nothing follows.

add no-case to get DAB combos

Why use regex for this?


if(someString.StartsWith("dab", StringComparison.OrdinalIgnoreCase)) {
    // stuff.
}

We could do that but it would involve using the custom validator and several lines of javascript rather than ([Dd][Aa][Bb])\s* !

It needs to be dab as the first 3 letters, with any combo of upper and lower case (daB, DaB etc) other than that anything is fine!

cheers

Thanks both for your input. We have:

([Dd][Aa][Bb])\s* to match what we want with no spaces. Couldn’t get the ignore case sensitivity to work though!

cheers

More info?? What can follow? What can proceed? What about whitespace?

Is it ok to match dabdabdab? dabba-doo? what about Dab, dAb, daB or DAB?

It will be a simple regex if you’re okay with matching all that and more.

edit oh what the hell…
^dab

client side validation! :slight_smile:

Sorry, but no, it doesn’t. It tells the regex engine the last character should occur zero or times.

whoops yes, thanks for catching that— I was using my shell regexes today!!

Sorry, but no, it doesn’t. It tells the regex engine the last character should occur zero or times.
So the regex you gave matches da, dab, dabb, dabbb, dabbbb, dabbbbb etc

Just ^dab is fine :slight_smile:

If you want to make sure the regex is proceeded by something, use ^dab.
. matches any character