473,396 Members | 1,784 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,396 software developers and data experts.

Regular Expression that matchs more than one condtion

I am parsing HTML and have source text like this

<A,A>

that I would like to retreive all of the "A"s from using an expression like

<[^>]*?(?<content>A)[^>]*?>

Even though this will technically match both A's, it only returns the first
one. How can I return both "A"s

Thanks

Earl
Nov 16 '05 #1
2 886
Try this:

<((?<content>A)|[^>])*>

You can iterate through the Captures collection of the named group 'content'
to get each A.
Alternatively, I think you could use:

(?<=<[^>]*)A(?=[^>]*)

With this, you iterate through the Matches in MatchCollection to get each A.

Brian Davis
http://www.knowdotnet.com


"Earl Teigrob" <ea******@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I am parsing HTML and have source text like this

<A,A>

that I would like to retreive all of the "A"s from using an expression like
<[^>]*?(?<content>A)[^>]*?>

Even though this will technically match both A's, it only returns the first one. How can I return both "A"s

Thanks

Earl

Nov 16 '05 #2
Thanks Brian, That worked perfectly. In fact, I decided I had better read
my regular expressions book so I can really get a grip on this stuff

Earl
"Brian Davis" <br***@knowdotnet.nospam.com> wrote in message
news:eU**************@TK2MSFTNGP12.phx.gbl...
Try this:

<((?<content>A)|[^>])*>

You can iterate through the Captures collection of the named group 'content' to get each A.
Alternatively, I think you could use:

(?<=<[^>]*)A(?=[^>]*)

With this, you iterate through the Matches in MatchCollection to get each A.
Brian Davis
http://www.knowdotnet.com


"Earl Teigrob" <ea******@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I am parsing HTML and have source text like this

<A,A>

that I would like to retreive all of the "A"s from using an expression

like

<[^>]*?(?<content>A)[^>]*?>

Even though this will technically match both A's, it only returns the

first
one. How can I return both "A"s

Thanks

Earl


Nov 16 '05 #3

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

Similar topics

5
by: sbd! | last post by:
I had a problem with string which have some \ chars at the end of the string. For example: $String = "I want this **** out of here\\\\\\\\\"; I needed to remove it useing regular...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
7
by: hungrymind | last post by:
Hi all, I am developing some control (textbox based), to validate inputs to that control I am using regular expression, where pattern is generated dynamically. I need to identify what all...
2
by: User N | last post by:
I need a re that matchs an HTML anchor element, extracting the href and text, given some of the text. For example, given the following two line input: <a href="a">bogus</a><a...
2
by: Brian Kitt | last post by:
I have a process where I do some minimal reformating on a TAB delimited document to prepare for DTS load. This process has been running fine, but I recently made a change. I have a Full Text...
11
by: jojobar | last post by:
I have a aspx file (snippet shown below): ======= <td class="light-m1" id="rwCompleteButton" runat="server"><br/> <asp:ImageButton CssClass="clear-m1" runat="server" CommandName="Complete"...
5
by: Josema | last post by:
Hi to all, i did this regular expresion <!--!.*!--> that matchs all occurrences of type <!--!Name!--> <!--!Description!--> and so on... I would like to know the regular expression to get...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
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...

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.