473,326 Members | 2,012 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,326 software developers and data experts.

"match" issues with non-alphanumberic characters

127 100+
Hi all,

I am using "match" to see if elements in one array match elements in another array.

My first array is "1.1,1.2,2.1" so I convert it to a string. Next, I have a loop that cycles through the second array, converts the current element of the second array to a string, and then uses "match" to see if this occurs in the string corresponding to the first array.

"match" seems to get confused if I have an element such as "2.2" in the second array, as it thinks it matches "....2,2...." in the string corresponding to the first array.

Any ideas on how to fix this?

Thanks in advance
Apr 30 '09 #1
7 1691
acoder
16,027 Expert Mod 8TB
Why bother with strings when you have the values and can match directly?

When using match, the string is converted to a regular expression where the dot character can match any character including comma.
Apr 30 '09 #2
phub11
127 100+
Thanks for the reply.

I thought it would be quicker using "match" with string than having a subloop (for each element within array 2) within a loop (for each element within array 1).

Am I misunderstanding your suggestion?

Thanks!
Apr 30 '09 #3
acoder
16,027 Expert Mod 8TB
Fair enough, though I'm not sure about the exact performance differences.

For your problem, replace the "." with "\.", so 2.2 becomes 2\.2, so that the dot is matched and not any character.
May 1 '09 #4
phub11
127 100+
Thanks for the reply.

In the end, my work around was to change "string.split(',')" to "string.split('X')".

EDIT: Oops, that doesn't work!

Thanks again!
May 1 '09 #5
acoder
16,027 Expert Mod 8TB
Why would you be using split (producing an array) when you already had one in the first place?!

As I said, use the backslash \ to escape the dot.
May 1 '09 #6
phub11
127 100+
Sorry, hadn't looked at it until last night and forgot where I was!

The problem with your suggestion in that I'd have to edit a lot of other functions (each element is called from a cell ID in a table).

The correct work around is: string1 = string.replace(/,/g, "XXX")

Works for me so far.
May 1 '09 #7
acoder
16,027 Expert Mod 8TB
That would work, but be careful about the fact that it's a fix because the dot is still matching any character. It doesn't match 2,2 because that's now become 2XXX2.
May 1 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: kmunderwood | last post by:
I am trying to combine "if match=" and "when test" I am a newbie, and have made both work separately, but I can not seem to combine them. This is my xml("index.xml")page(I can not change this,...
7
by: Chris Mantoulidis | last post by:
I was wondering if there was something like a "match" class in the std. By match class I mean something like a search tool. That is I will tell it in what text to search and WHAT to search for. The...
1
by: myth.drannon | last post by:
Hi , I'm trying to find a simple solution to this question.. ( not just making two match parts) I have <xsl:template match=" one | two " > and then I want to test what match I have and do...
32
by: Licheng Fang | last post by:
Basically, the problem is this: 'do' Python's NFA regexp engine trys only the first option, and happily rests on that. There's another example: 'oneself' The Python regular expression...
2
by: Papkin | last post by:
Hi if ( eregi("^/a-zA-Z0-9±ęćłń󶿼ˇĆĘŁŃÓ¦¬Ż\.\/\/-]{2,65}$","Merry & Cat") ) return true; else return false; I'd like to match also "&" but this regexp above does not do...
1
by: Pythor | last post by:
OK I'm trying to create a sql query on our as400. I have a main table like this: acct prf acct no. sku AAA 123 ABCD AAA 123 XYZ I have...
3
by: Good Man | last post by:
Hi there Ideally, I'd like to create one javascript function and pass the file extension i'm looking for to see if its there: <input type="file" onchange="checkFile('pdf',this)" /> and then...
1
by: patelxxx | last post by:
Hi Guy's, I'm getting the error: "Username or password did not match" BEFORE I even enter a username and password, can someone help? 1) The site I'm accessing is:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
1
by: Shllpp 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.