Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: *fixed*Problem with <> and regex

by Laurent_R (Canon)
on Mar 11, 2014 at 22:44 UTC ( [id://1077921]=note: print w/replies, xml ) Need Help??


in reply to *fixed*Problem with <> and regex

If you really want to reduce:
<span class="author-name" itemprop="author">Romaxton</span>
you could use something like this (untested):
s/<[^>]+(\w+)/$1/;

Replies are listed 'Best First'.
Re^2: *fixed*Problem with <> and regex
by AnomalousMonk (Archbishop) on Mar 11, 2014 at 22:54 UTC

    That doesn't actually work:

    c:\@Work\Perl>perl -wMstrict -le "my $s = '<span class=\"author-name\" itemprop=\"author\">Romaxton</sp +an>'; ;; $s =~ s/<[^>]+(\w+)/$1/; print qq{'$s'}; " 'r">Romaxton</span>'
      Yes, you are right. I was not in a position to test when I posted and I missed parts of it. I was thinking about something like this (assuming the string is in $_):
      s/<[^>]+>(\w+).*/$1/;
      which does work, but there are actually some easier ways, such as:
      print $1 if />(\w+)</;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1077921]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-29 08:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found