in reply to Help with RegEx

The regular expression .*? can be translated to English as "match 0 or more of any character in a non-greedy fashion". That last bit is your problem - the shortest string of arbitrary characters that can be matched following stylesheet is, of course, "". You may mean to have something closer to

while ($line_in =~ m{<^(.*?)stylesheet(.*?)$>}gis)

which anchors your regular expression at the start and end of your string. In this context, you probably don't want non-greedy matching, so you could also use

while ($line_in =~ m{<(.*)stylesheet(.*)>}gis)

See perlre and perlretut for more info.

Replies are listed 'Best First'.
Re^2: Help with RegEx
by mr_p (Scribe) on Jul 01, 2010 at 16:05 UTC

    Thanks so much.

    Is there a way I can get href value in one step process or I have to do another step of regex for it.
Re^2: Help with RegEx
by mr_p (Scribe) on Jul 01, 2010 at 16:09 UTC

    Thanks so much.

    Is there a way I can get href in one step process or I have to do another step of regex for it.

    The results are weird...It is stripping off everything after style sheet in this line '<?xml-stylesheet href=\"perl1.css\" type=\"text/css\"?>'

      Maybe you want to use a proper HTML parser, like HTML::Parser instead?

        It takes close to 500ms. If I can do it though RegEx isn't that less of hassle.
        But, I noticed it takes really long to load into HTML.