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

retrieving <a> tags in a string with regexp

Hi,

I would like to get an array of <ahtml tags og a string.

I have done this but it doesnt works :

var reg;
var str='Bonjour, ceci est un test, une <a href="phrase.php">phrase</a>
décrivant un <img src="mot.gif" alt="mot"assez <a
href="important.php">important</a>';

reg=new RegExp('<a [^<|>]+>([^<|>]*)<\/a>', "gi");

matchstr=reg.exec(str);
if (matchstr == null)
alert("No match");
else
{
alert(matchstr.length);
for (var i = 0; i < matchstr.length; i++)
{
alert(matchstr[i]);
}

}
My BUG :
matchstr only contains <a href="phrase.php">phrase</abu not <a
href="important.php">important</a!!
How to do then ?

Thanks for any help on it !

Regards

Fred
Sep 14 '06 #1
1 1062
Fred wrote:
I would like to get an array of <ahtml tags og a string.

I have done this but it doesnt works :

var reg;
var str='Bonjour, ceci est un test, une <a href="phrase.php">
phrase</adécrivant un <img src="mot.gif" alt="mot"assez <a
href="important.php">important</a>';

reg=new RegExp('<a [^<|>]+>([^<|>]*)<\/a>', "gi");

matchstr=reg.exec(str);
if (matchstr == null)
alert("No match");
else
{
alert(matchstr.length);
for (var i = 0; i < matchstr.length; i++)
{
alert(matchstr[i]);
}

}
My BUG :
matchstr only contains <a href="phrase.php">phrase</abu not <a
href="important.php">important</a!!
I would do something like

<pre>
<a href="http://www.google.com">1</a>
<A hRef="http://yahoo.com">2</A>
<a target="_blank" href = "file.php">3</a>
<a
href="javascript:alert('hi')" abc def>4</a>
<a href="#" OnClick="alert('hi')">5</a>
</pre>

<script type='text/javascript'>
for (var i=0; i<document.getElementsByTagName('a').length; i++)
alert(document.getElementsByTagName('a')[i]);
</script>

--
Bart

Sep 16 '06 #2

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

Similar topics

8
by: Beznas | last post by:
Hi All; I'm trying to create an ASP function called CleanX that removes the punctuation and some characters like (*&^%$#@!<>?"}|{..) from a text string I came up with this but It...
2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
8
by: Mark | last post by:
We have a multi-line textbox that users copy and paste email text into. The pasted text frequently will contain a tag like <blah@aol.com> or similar. I believe .NET is protecting itself from code...
1
by: Neil Zanella | last post by:
Hello, I would like to do the following: <form method="post" action="<%= Request.ServerVariables %>" runat="server"> The reason I would like to do this is twofold:
7
by: BluDog | last post by:
Hi I am trying to store an image in an xml file, i vcan store it fine but the retreval is a bit of a problem: To String: Dim ms As New IO.MemoryStream Dim arrImage() As Byte...
6
by: buzzweetman | last post by:
Many times I have a Dictionary<string, SomeTypeand need to get the list of keys out of it as a List<string>, to pass to a another method that expects a List<string>. I often do the following: ...
3
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
14
by: Michael | last post by:
Since the include function is called from within a PHP script, why does the included file have to identify itself as a PHP again by enclosing its code in <?php... <?> One would assume that the...
2
by: -Karl | last post by:
Couls someone please advise me on this error. What I am trying to do is be able to convert an XML document into arrays. I read that the subs & functions have to be in <scripttags. Thanks! ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.