regex help

R

Rainer Collet

hi!

i need a regex that matches all link-texts in html that are longer
than 17 characters. i started with

/<a.*?href=.*?>[^<\/a>]{18,}<\/a>/i

but the negated char-class [^<\/a>] is wrong, because if there is any
of the characters of the class in the link-text is does not match. so
it must be replaced by an expression that means: match 17 chars or
more, if there is no "</a>" included in them.

has anybody an idea?

- rainer
 
P

phaylon

Rainer said:
but the negated char-class [^<\/a>] is wrong, because if there is any of
the characters of the class in the link-text is does not match. so it must
be replaced by an expression that means: match 17 chars or more, if there
is no "</a>" included in them.

Have a look at 'perldoc -q greedy'.

hth,phay
 
J

John Bokma

Rainer said:
hi!

i need a regex that matches all link-texts in html that are longer
than 17 characters. i started with

Use HTML::TreeBuilder for example and:

my @elements = $root->look_down(
_tag => 'a',
sub { length( $_[0]->as_text ) > 17 }
};

(untested)
 
R

Rasto Levrinc

Rainer said:
hi!

i need a regex that matches all link-texts in html that are longer
than 17 characters. i started with

/<a.*?href=.*?>[^<\/a>]{18,}<\/a>/i

has anybody an idea?

You should do it with HTML::TreeBuilder or something, but if it is an
exercise, I came up with this solution:

my @res = /<a\s+href=.*?>((?:.(?!<\/a>)){16,}.)<\/a>/ig;

(It doesn't matter that {16,} is greedy)

Rasto
 
R

Rasto Levrinc

Rasto said:
Rainer said:
hi!

i need a regex that matches all link-texts in html that are longer
than 17 characters. i started with

/<a.*?href=.*?>[^<\/a>]{18,}<\/a>/i

has anybody an idea?

You should do it with HTML::TreeBuilder or something, but if it is an
exercise, I came up with this solution:

my @res = /<a\s+href=.*?>((?:.(?!<\/a>)){16,}.)<\/a>/ig;

Correction:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

RegEx 0
Help with my responsive home page 2
Idk need help in editing this source code 0
I need help fixing my website 2
regex question 7
Help with code 0
Help with dynamic regex 14
Help in hangman game 1

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top