XML and Regular Expression and JavaScript.

Posted on 2013-09-09
Medium Priority
Last Modified: 2013-09-09
Hi All,

This one is throwing me for a loop. It's just probably something simple I am missing and I'm not catching it.

I have an XML and in the XML I have like this node:

<File RegEx="^((([a-zA-Z]\:)|(\\))(((\\{1})[^\\\ ]([^/:*?<>""|\\]*))+)[\\]).*\.(?!xml$|tif$)[^.]+" Description="TEST File">

The node has an attribute for a regular expression.  The xml will get loaded in with Javascript.

Now, the problem I am having is on the regular expression: mainly with this part of the regular expression - ([^/:*?<>""|\\]*))+)[\\]). Notice the "".

The intent of the regular expression is to exclude files that ARE NOT an .xml or tif extension. This is where the part of the regular expression comes in. I need to be able to accommodate for either a letter:\ or a UNC. (C:\Test or \\XX.XX.XX.XX\Test).

One might think to just escape the quotes with a \"\". That didn't work. One might think to change the double quotes to single quotes ('") instead of (""). Well, did that and it didn't work either. When I have the escaped double quotes it is not a valid XML and cannot even really save it unless I open it in notepad and change it. BUT I cannot even open in as a straight XML in IE.

When I change it to a single quote, I am able to save it as an XML. However, I am still unable to open it in IE.

How can I do this? I tried to escape and that didn't work. I tried to change to single quotes and that didn't work.

Any positive information on this would greatly be appreciated.

Question by:davism
  • 3
  • 3
LVL 35

Expert Comment

by:Terry Woods
ID: 39478348
Try replacing it with &quot;

<File RegEx="^((([a-zA-Z]\:)|(\\))(((\\{1})[^\\\ ]([^/:*?<>&quot;|\\]*))+)[\\]).*\.(?!xml$|tif$)[^.]+" Description="TEST File">

Open in new window


Author Comment

ID: 39478415
Nope, that doesn't work either. You cannot open it in IE. Let alone there are 2 quotes. So you would have to do &quot;&quot;

But I did one and then tried 2. Neither worked.
LVL 35

Expert Comment

by:Terry Woods
ID: 39478419
Are you able to provide a stripped down sample file that I can try opening in IE myself?
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.


Author Comment

ID: 39478432
Yeah, it you do something like this:

<?xml version="1.0" ?>

   <File RegEx="^.*\.(?!xml$|tif$)[^.]+" Description="TEST File">

If you put the above in a file then you can open the file in IE. Or if you just take the Test.xml file you will see you can.
LVL 35

Accepted Solution

Terry Woods earned 1200 total points
ID: 39478449
Looks like the < and > characters need escaping too:
<File RegEx="^((([a-zA-Z]\:)|(\\))(((\\{1})[^\\\ ]([^/:*?&lt;&gt;&quot;&quot;|\\]*))+)[\\]).*\.(?!xml$|tif$)[^.]+" Description="TEST File">

Open in new window

Ampersands would need escaping too, if used. More detail here: http://www.w3.org/TR/xml/#syntax

Author Closing Comment

ID: 39478470
Yep, that was it! Didn't think I have to specify the greater than and everything too. Go figure.

Thanks for the info and assistance.

Greatly appreciated!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question