473,654 Members | 3,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"match" issues with non-alphanumberic characters

127 New Member
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 1706
acoder
16,027 Recognized Expert Moderator MVP
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 New Member
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 misunderstandin g your suggestion?

Thanks!
Apr 30 '09 #3
acoder
16,027 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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
2069
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, it comes to me this way. <?xml version="1.0" encoding="iso-8859-1" ?>
7
1677
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 format of what I want it to find would be something like: "abc?efg*mnopq?st*z" I hope you understand what I mean. :) So it a class (or anyway SOMETHING) in the std header files that is something like that or do I have to implement it myself?
1
1233
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 something accordinly. I was thinking <xsl:if test="match=one" > will work but it's not ....
32
14653
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 engine doesn't exaust all the
2
1454
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 this, adding \& does not help. Any ideas?
1
2255
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 another table
3
2474
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 have the function something like (w/ Prototype)
1
2352
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: http://www.valuemapping.co.uk/VMSE/ 2) Then I click/select the following application: "VMSE Reporting" and get the above error. The CGI script for this is:
0
8294
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8709
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8596
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2719
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.