473,508 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

regEx for HTML element

Hello,
I am trying to parse a HTML page and want to replace the input
element

The following code fails all the time.

var ex = "<input type=\"hidden\" name=\"__VIEWSTATE\"
id=\"__VIEWSTATE\"
value=\"/wEPDwULLTE2NjEyNTI0MThkGAEFEHNlY3Rpb25zR3JpZFZpZXc PZ2QN271==
/>";
var regEx = new RegExp("<\s*input[^>]*>(.*?)\s*/");
if (ex.match( regEx))
{
alert('match');
}
else
{
alert ('no match');
}
any help would be great!

Thanks,
Srini.

Jan 3 '07 #1
1 1646
wrote on 03 jan 2007 in comp.lang.javascript:
Hello,
I am trying to parse a HTML page and want to replace the input
element

The following code fails all the time.

var ex = "<input type=\"hidden\" name=\"__VIEWSTATE\"
id=\"__VIEWSTATE\"
value=\"/wEPDwULLTE2NjEyNTI0MThkGAEFEHNlY3Rpb25zR3JpZFZpZXc PZ2QN271==
/>";
var regEx = new RegExp("<\s*input[^>]*>(.*?)\s*/");
if (ex.match( regEx))
{
alert('match');
}
else
{
alert ('no match');
}
For replacing I would use replace() not match():
<div id='container'>
======== other things ========
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwULLTE2NjEyNTI0MThkGAEFEHNlY3Rpb25zR3JpZFZpZXc PZ2QN271" />
======== other things ========
</div>

<script type='text/javascript'>
var s = document.getElementById('container')

s.innerHTML =
s.innerHTML.replace(/<input ([^>]*)>/gi,'<br>Replacing ...<br>(arguments:
$1)<br>')

</script>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1468
by: G. Stewart | last post by:
The objective is to extract the first n characters of text from an HTML block. I wish to preserve all HTML (links, formatting etc.), and at the same time, extend the size of the block to ensure...
4
9703
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
17
3941
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
2
1362
by: .NET Developer | last post by:
Hello, I'm trying to write a RegEx that will find all occurances of a particular type of HTML anchor <a> element in a big block of HTML. Here are the pattern requirements - they consist of certain...
5
3038
by: Digital.Rebel.18 | last post by:
I'm trying to figure out how to extract the keywords from an HTML document. The input string would typically look like: <meta name='keywords' content='word1, more stuff, etc'> Either single...
13
2342
by: Chris Lieb | last post by:
I am trying to write a regex that will parse BBcode into HTML using JavaScript. Everything was going smoothly using the string class replace() operator with regex's until I got to the list tag....
4
2284
by: 28tommy | last post by:
Hi, I'm trying to find scripts in html source of a page retrieved from the web. I'm trying to use the following rule: match = re.compile('<script + src=+>') I'm testing it on a page that...
3
2691
by: aspineux | last post by:
My goal is to write a parser for these imaginary string from the SMTP protocol, regarding RFC 821 and 1869. I'm a little flexible with the BNF from these RFC :-) Any comment ? tests= def...
0
1724
by: Karch | last post by:
I have these two methods that are chewing up a ton of CPU time in my application. Does anyone have any suggestions on how to optimize them or rewrite them without Regex? The most time-consuming...
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7125
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...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7499
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...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4709
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...
0
1561
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 ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
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...

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.