J
Jason C
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?
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?