![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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. |
#3
| |||
| |||
|
|
Andrew Poulos <ap_prog (AT) hotmail (DOT) com> writes: 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 |
#4
| |||
| |||
|
|
Andrew Poulos <ap_prog (AT) hotmail (DOT) com> writes: 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; |
#5
| |||
| |||
|
|
Lasse Reichstein Nielsen wrote: First, why use a regexp? There's about a dozen items that start with "cmi.interactions" bu have different endings. |
![]() |
| Thread Tools | |
| Display Modes | |
| |