473,321 Members | 1,877 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,321 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 1313
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.