Andrew Poulos <ap_prog@hotmail.comwrites:
Quote:
I have a string that looks like this
>
"cmi.interactions.fred.id"
>
I need to test that:
- the first part of the string is "cmi.interactions." (case sensitive).
- the last part of the string is ".id" (case sensitive).
- that there's 1 or more characters between the 2nd and third dots (in
the above example its "fred")
- that there's only 3 dots in the whole string
>
Could someone please write a regexp for me. I've had a few goes but it
keeps failing.
First, why use a regexp?
var valid =
string.length 20 &&
string.substring(0,17) == "cmi.interactions." &&
string.substring(string.length-3) == ".id" &&
string.indexOf(".",17) == string.length - 3;
But if you insist on a regexp:
/^cmi\.interactions\.[^.]+\.id$/
/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'