473,789 Members | 2,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex Question

I have a text like this
<a href=aaaa>somet hing </a><a href=aaaa>somet hing </a><a href=aaaa>somet hing
</a><a href=aaaa>somet hing </a><a href=aaaa>somet hing </a>
i have to extract each "<a href=aaaa>somet hing </a> "out i did something
like this
<A[^>]*>.*</A>

but it returns the whole string rather than individual "<a
href=aaaa>somet hing </a>"

Where am i going wrong.....

Nov 13 '05 #1
3 4570
Try the following expression:

<A[^>]*>.*?</A>

Notice the question mark to indicate a "lazy" matching so that it stops at
the first occurence of </A> and not at the last on the line.
Arild

"NotYetaNur d" <No*********@Ma trix.com> wrote in message
news:u6******** ******@TK2MSFTN GP11.phx.gbl...
I have a text like this
<a href=aaaa>somet hing </a><a href=aaaa>somet hing </a><a href=aaaa>somet hing </a><a href=aaaa>somet hing </a><a href=aaaa>somet hing </a>
i have to extract each "<a href=aaaa>somet hing </a> "out i did something
like this
<A[^>]*>.*</A>

but it returns the whole string rather than individual "<a
href=aaaa>somet hing </a>"

Where am i going wrong.....

Nov 13 '05 #2

The .* term is gobbling up the whole string. Use .*? (non-greedy gobble) or
just [^<]*.

There is a tradeoff, as always. .*? is slightly more expensive at
run-time, but it's a little clearer.

Jon

"NotYetaNur d" <No*********@Ma trix.com> wrote in message
news:u6******** ******@TK2MSFTN GP11.phx.gbl...
I have a text like this
<a href=aaaa>somet hing </a><a href=aaaa>somet hing </a><a href=aaaa>somet hing </a><a href=aaaa>somet hing </a><a href=aaaa>somet hing </a>
i have to extract each "<a href=aaaa>somet hing </a> "out i did something
like this
<A[^>]*>.*</A>

but it returns the whole string rather than individual "<a
href=aaaa>somet hing </a>"

Where am i going wrong.....

Nov 13 '05 #3
Thanks You ...
"NotYetaNur d" <No*********@Ma trix.com> wrote in message
news:u6******** ******@TK2MSFTN GP11.phx.gbl...
I have a text like this
<a href=aaaa>somet hing </a><a href=aaaa>somet hing </a><a href=aaaa>somet hing </a><a href=aaaa>somet hing </a><a href=aaaa>somet hing </a>
i have to extract each "<a href=aaaa>somet hing </a> "out i did something
like this
<A[^>]*>.*</A>

but it returns the whole string rather than individual "<a
href=aaaa>somet hing </a>"

Where am i going wrong.....

Nov 13 '05 #4

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

Similar topics

4
4381
by: engwar1 | last post by:
Not sure where to ask this. Please suggest another newsgroup if this isn't the best place for this question. I'm new to both vb.net and regex. I need a regular expression that will validate what people are entering as their new password. Must be between 6 and 10 characters Must be alphanumeric only Can not be the word "password" in any case ie "pAsSworD" should also be denied.
4
9772
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 numeric value according to an arbitrary regular expression.
2
3429
by: Tim Conner | last post by:
Hi, Thanks to Peter, Chris and Steven who answered my previous answer about regex to split a string. Actually, it was as easy as create a regex with the pattern "/*-+()," and most of my string was splitted. I am fascinated to the powerfull use of this RegEx class, so I wonder if it could go a step further. As a question, can regex be used to valid a set of different functions ? Example : Suppose I have to verify the correctness of an...
6
396
by: Du Dang | last post by:
Text: ===================== <script1> ***stuff A </script1> ***more stuff <script2> ***stuff B
17
3981
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 http://forta.com/books/0672325667/
5
5106
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated by a tool. ' Runtime Version: 1.1.4322.2032 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. ' </autogenerated>
6
5901
by: Martin Evans | last post by:
Sorry, yet another REGEX question. I've been struggling with trying to get a regular expression to do the following example in Python: Search and replace all instances of "sleeping" with "dead". This parrot is sleeping. Really, it is sleeping. to This parrot is dead. Really, it is dead.
7
2590
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward slash then some numbers. For some reason I am not getting that. It won't work at all in 2.0
6
4212
by: Phil Barber | last post by:
I am using Regex to validate a file name. I have everything I need except I would like the dot(.) in the filename only to appear once. My question is it possible to allow one instance of character but not two or more? example myfile.doc = good My.file.doc = not good if you could give an example of the expression pattern that would most helpful. thanks phil
6
2075
by: | last post by:
Hi all, Sorry for the lengthy post but as I learned I should post concise-and-complete code. So the code belows shows that the execution of ValidateAddress consumes a lot of time. In the test it is called a 100 times but in my real app it could be called 50000 or more times. So my question is if it is somehow possible to speed this up and if so how
0
9506
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
10404
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10193
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...
1
10136
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
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...
1
7525
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4089
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
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.