Home: Perl Programming Help: Regular Expressions:
Help with REG EXP Perl Code basic question



GuerillaSquad
Novice

Aug 31, 2009, 11:16 AM


Views: 7194
Help with REG EXP Perl Code basic question

I have a piece of PERL code. I know what the code does but I cannot figure out in any documentation the usage. I will put the short code line here and then ask my question...

s#<(/?)H1>#<$1H2>#g;

Q. What does the /? do?

I know the () are tagging so I can call $1 later, and I can figure out the /? is saying anything before "H1", but how is it saying that?

Thanks,
Mike


---------------------------
~The path to perfection is never clear~


KevinR
Veteran


Aug 31, 2009, 11:47 AM


Views: 7192
Re: [MikeDexter] Help with REG EXP Perl Code basic question

In that context the "?" is a quantifier meaning "zero or one" so it means if there are zero or one forward slashes "/?" the match is true. It will match the opening and closing H1 html tags:

<H1>
</H1>

Its turning all H1 tags into H2 tags.
-------------------------------------------------


GuerillaSquad
Novice

Aug 31, 2009, 11:52 AM


Views: 7189
Re: [KevinR] Help with REG EXP Perl Code basic question

KevinR,

Very Clever.

I was not thinking about the closing tag preservation. Thanks for the response.

Mike


---------------------------
~The path to perfection is never clear~