John W. Krahn am Dienstag, 7. März 2006 00.12:
> Adam W wrote:
> > JupiterHost.Net wrote:
> >>>> $text =~ s!(.*?)\((.*?)\)!<a href="$2" alt="$2">$1</a>!g;
[...]
> >> Same exact regex as above:
> >>
> >> $test =~ s{ (.*?) [(] (.*?) [)] }
> >> {<a href="$2" alt="$2">$1</a>}xmsg;
[...]
> > Can you tell me what the function of the square-brackets are for regexps?
> > How are they different than regular parens?
>
> '[' and ']' define a character class, but you don't really need a character
> class in your example.
Adam,
just to sum up:
$test =~ s{ (.*?) \( (.*?) \) }
{<a href="$2" alt="$2">$1</a>}xsg;
- "\(" instead of "[(]": more readable
- no /m modifier : unnecessary without ^/$-anchors
- /s : may be appropriate for your html source text
:-)
Hans
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>