473,387 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

regexp help on part match

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.

Andrew Poulos
Aug 27 '08 #1
4 1317
Andrew Poulos <ap*****@hotmail.comwrites:
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.'
Aug 27 '08 #2
Lasse Reichstein Nielsen wrote:
Andrew Poulos <ap*****@hotmail.comwrites:
>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?
There's about a dozen items that start with "cmi.interactions" bu have
different endings.
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
Thank you.

Andrew Poulos
Aug 27 '08 #3
pr
Lasse Reichstein Nielsen wrote:
Andrew Poulos <ap*****@hotmail.comwrites:
>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;
Alternatively:

var parts = string.split(".");
var isValid = parts.length == 4 && parts[0] == "cmi" &&
parts[1] == "interactions" && parts[2] != "" && parts[3] == "id";
Aug 27 '08 #4
Andrew Poulos <ap*****@hotmail.comwrites:
Lasse Reichstein Nielsen wrote:
>First, why use a regexp?

There's about a dozen items that start with "cmi.interactions" bu have
different endings.
You'll need different regexps for those too.
But it's not a problem to generalize:

function isValid(string, ending) {
var el = ending.length;
var sl = string.length;
return string.length 18+el &&
string.substring(0,17) == "cmi.interactions." &&
string.indexOf(".",17) == sl-el-1 &&
string.substring(sl-el) == ending;
}
/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: python_charmer2000 | last post by:
I want to match several regexps against a large body of text. What I have so far is similar to this: re1 = <some regexp> re2 = <some regexp> re3 = <some regexp> big_re = re.compile(re1 +...
1
by: joh12005 | last post by:
Hello, here is a trouble that i had, i would like to resolve it with python, even if i still have no clue on how to do it. i had many small "text" files, so to speed up processes on them, i...
20
by: RobG | last post by:
I'm messing with getPropertyValue (Mozilla et al) and currentStyle (IE) and have a general function (slightly modified from one originally posted by Steve van Dongen) for getting style properties:...
0
by: Chris Croughton | last post by:
I'm trying to use the EXSLT regexp package from http://www.exslt.org/regexp/functions/match/index.html (specifically the match function) with the libxml xltproc (which supports EXSLT), but...
3
by: jasonkester | last post by:
Just a heads up for anybody that comes across this in the future. Noticed a strange behavior in RegExp.test() today. Check out the following code. It will alternately display "chokes" and null,...
8
by: Dmitry Korolyov | last post by:
ASP.NET app using c# and framework version 1.1.4322.573 on a IIS 6.0 web server. A single-line asp:textbox control and regexp validator attached to it. ^\d+$ expression does match an empty...
4
by: Jiri Fogl | last post by:
I'm trying to build a regular expression (POSIX extended). One part of it has to match any text not containing a slash except standalone two dots (..), but I can't find the way to say something...
11
by: HopfZ | last post by:
I coudn't understand some behavior of RegExp.test function. Example html code: ---------------- <html><head></head><body><script type="text/javascript"> var r = /^https?:\/\//g;...
6
by: runsun pan | last post by:
Hi I am wondering why I couldn't get what I want in the following 3 cases of re: (A) var p=/(+-?+):(+)/g p.exec("style='font-size:12'") -- // expected
27
by: SQL Learner | last post by:
Hi all, I have an Access db with two large tables - 3,100,000 (tblA) and 7,000 (tblB) records. I created a select query using Inner Join by partial matching two fields (X from tblA and Y from...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.