How ot formulate a REGEX for this?

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
wren9
Forum Newbie
Posts: 9
Joined: Sat May 23, 2009 1:50 am

How ot formulate a REGEX for this?

Post by wren9 »

Hi
Let say i have an html codes below,

Code: Select all

 
<html>
<head>
</head>
 
<body>
<h4>this is H4 heading one</h4>
    <a href="domain.com">one</a>
    <a href="domain.com">two</a>
    <a href="domain.com">three</a>
<h4>this is H4 heading two</h4>
</body>
</html>
 
What i want is to get all the link between H4 heading one and H4 heading two.

Can you show me the right REGEX syntax for this please.

Thank you in advance.
Last edited by Benjamin on Tue May 26, 2009 11:18 am, edited 1 time in total.
Reason: Changed code type from text to html.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: How ot formulate a REGEX for this?

Post by prometheuzz »

You didn't mention that there can be links outside these tags, so this regex will work just fine:

Code: Select all

'/(?<==")[^"]+(?=")/'
wren9
Forum Newbie
Posts: 9
Joined: Sat May 23, 2009 1:50 am

Re: How ot formulate a REGEX for this?

Post by wren9 »

prometheuzz wrote:You didn't mention that there can be links outside these tags, so this regex will work just fine:

Code: Select all

'/(?<==")[^"]+(?=")/'

You are correct, there is links outside.

can you show me that too please.

Thank you.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: How ot formulate a REGEX for this?

Post by prometheuzz »

wren9 wrote:
prometheuzz wrote:You didn't mention that there can be links outside these tags, so this regex will work just fine:

Code: Select all

'/(?<==")[^"]+(?=")/'

You are correct, there is links outside.

can you show me that too please.

Thank you.
Well, I can help you with it. What have you tried yourself so far?
Post Reply