Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Replace empty alt tag on <img> tag

by vlearner (Initiate)
on Jan 20, 2022 at 12:06 UTC ( [id://11140639]=note: print w/replies, xml ) Need Help??


in reply to Re: Replace empty alt tag on <img> tag
in thread Replace empty alt tag on <img> tag

can I do the same with regular expression??

Replies are listed 'Best First'.
Re^3: Replace empty alt tag on <img> tag
by choroba (Cardinal) on Jan 20, 2022 at 12:18 UTC
    Generally, no.
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Generally yes, at least since Perl regex are turing complete

      The real question should be: Is it possible with a simple regex?

      Answer: No.

      A regex parsing HTML wouldn't be less complex than a full scale HTML parser and consist of various nested sub expressions.

      Certainly not a one liner.

      - Ron

        Unless you're talking about mucking with specific bits of *ML text with specific, limited formatting that you know is never going to vary then even letting regexen enter anywhere near your thoughts is probably heading deep into now you have two problems territory.

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

        Generally yes

        Please do feel free to share your implementation.

Re^3: Replace empty alt tag on <img> tag -- dont use a regex
by Discipulus (Canon) on Jan 20, 2022 at 12:17 UTC

      > here at the monastery only tybalt89 owns a special permission to deal with HTML or XML using regular expressions

      Agreed that tybalt89 has earned it. To nitpick though, I think TheDamian is also worthy of this special permission.

      The PPR module provides a single regular expression that defines a set of independent subpatterns suitable for matching entire Perl documents

      -- from PPR by TheDamian (as if you couldn't guess ;-)

      See also these comments by kcott and haukex, discussing the differences between PPR and PPI.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-03-28 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found