Regex: match double OR single quote



I'm struggling with what I thought was a simple thing, and I'm hoping you guys can help.

I have a string that may contain a ", ', or neither. So, I wrote this in the regex:

["|']*

But this doesn't match anything.

Here's the complete code:

# $text comes from a form, so this is just a sample
$text = <<EOF;
<img src="<a href='http://www.example.com/whatever.jpg'
target='_new'>
http://www.example.com/whatever.jpg</a>"
width="300" height="300" border="0">
EOF

# Regex; line breaks added here for the sake of reading
$text =~ s/<img(.*?)src=
["|']*\s*<a.*? href=
["|']*\s*(.*?)
["|']*.*?>(.*?)<\/a>
["|']*(.*?)>
/<img src="$2"$1$4>/gsi;

If I change ["|']* to whatever I have hard coded, then it works fine, so I know the issue is with that pattern. So how do I correctly match them?
.



Relevant Pages

  • Re: how to split a string using ,fixed character length, variable text delimmiter
    ... Regex is very new to me, I would have been completely lost without your ... It still has one capture group that is absolutely necessary to make the ... instead and picked out the pieces from the string "manually". ... including the idea of reading the whole 14MB file into a string - but I ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Regular expression rejecting invalid files
    ... Since you're reading the entire file into a string before executing ... your regex, the start of file is the start of string. ...
    (microsoft.public.dotnet.languages.vb)
  • Regex
    ... I want to regex a 400Mb file. ... Instead of reading it all into a string and ... passing that into an expression is it possible to point regex to a file for ...
    (microsoft.public.dotnet.languages.vb)
  • Regex File contents
    ... I want to regex a 600Mb file. ... Instead of reading it all into a string and ... passing that into an expression is it possible to point regex to a file for ...
    (microsoft.public.dotnet.general)
  • Re: Regex Question
    ... We start by compiling a regex: ... Then we define a pattern string. ... converts backslash combinations as special characters, ... Regular expressions use a lot of backslashes, and so it is useful to ...
    (comp.lang.python)