Regexp to extract value of src attribute; handles single-quoted values, double-quoted values, and values without quotes (they must not contain any whitespace or quotes).

my $reSqString = qr{
  \'
  [^\']*
  \'
}x;

my $reDqString = qr{
  \"
  [^\"]*
  \"
}x;

my $reAttrValue = qr{
  (?: $reSqString | $reDqString | [^\'\"\s]+ )
}x;

my $reImgSrc =
    qr{
      <[iI][mM][gG]
        \s+
      (?: \w+ \s*=\s* $reAttrValue \s+ )*
      [sS][rR][cC] \s*=\s*
      (?: (?:\'([^\']+)\') | (?:\"([^\"]+)\") | ([^\'\"\s]+) )
      (?: \s+ \w+ \s*=\s* $reAttrValue )*
      \s*/?>
    }x;
  • testhtmlregexp: Script to test a regexp for extracting an attribute value from an HTML tag
Topic attachments
I Attachment Action Size Date Who Comment
testhtmlregexpEXT testhtmlregexp manage 1.8 K 20 Feb 2009 - 22:47 IsaacLin Script to test a regexp for extracting an attribute value from an HTML tag
Topic revision: 20 Feb 2009, IsaacLin
 
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. see CopyrightStatement. Creative Commons LicenseGet Foswiki at sourceforge.net. Fast, secure and Free Open Source software downloads