By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,717 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,717 IT Pros & Developers. It's quick & easy.

REgular expression to match a XML tag

P: n/a
Hi All,

I am trying to match an XML tag using JS regular expressions. The
pattern I am using is

pattern="/(<" + tagname + ">)" + "(*)" + "(<." + tagname +
">/g)";

where I want to replace the tagname variable with the name of the tag
which I want to search for. Unfortunately this doesn't work. If I
replace the tagname variable with the actual tag's name it works.
Any idea how to fix this issue?

If any of you could post a script that could do this it would be
great.

Thanks
Karthik

Nov 2 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi All,

MOdified the pattern to
var patt="(<" + tagname + ">)" + "(*)" + "(<." + tagname +
">)";

without the intial / and ending /g still no go...
On Nov 1, 11:28 pm, Karthik <karthik....@gmail.comwrote:
Hi All,

I am trying to match an XML tag using JS regular expressions. The
pattern I am using is

pattern="/(&lt;" + tagname + "&gt;)" + "(*)" + "(&lt;." + tagname +
"&gt;/g)";

where I want to replace the tagname variable with the name of the tag
which I want to search for. Unfortunately this doesn't work. If I
replace the tagname variable with the actual tag's name it works.
Any idea how to fix this issue?

If any of you could post a script that could do this it would be
great.

Thanks
Karthik


Nov 2 '07 #2

P: n/a
Karthik wrote:
var regexpr= new RegExp("(&lt;" + tagname + "&gt;)([A-Z]*[[a-z]*[0-9]*)
(&lt;." + tagname + "&gt;)");
apply a exec of this pattern on any string/html source/xml file, it
will fetch you the values between the tags..
one word of warning though if the tag has got child tags, it will
retrieve all the child tags also :)
And that's only the very beginning :-)

Take a look at

http://groups.google.com/group/comp....b006db41efc7b/

to get idea about the complexity of real XML string parsing.

Do yourself a favour and load it into the XML parser.

--
Bart

Nov 3 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.