Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Regular expression

by JavaFan (Canon)
on Jun 05, 2009 at 14:34 UTC ( #768810=note: print w/replies, xml ) Need Help??


in reply to Regular expression

I presume that your brackets cannot be nested? Because in your example strong, all the dollars are between brackets. (Note also that as is, we cannot deduce there are dollar signs in $line, as $10 and $s are two interpolated variables. But let's assume there's a lone q before the first double quote).

Assume that the above is true, and that all brackets are balanced, I'd write something like:

{ no warnings 'uninitialized'; $line =~ s/(<[^>]*>|\$[0-9])|\$/$1/g; }
Alternatively, keep the warning, replace the replacement with $1 || "" and use /e to eval the replacement.

Replies are listed 'Best First'.
Re^2: Regular expression
by John M. Dlugosz (Monsignor) on Jun 05, 2009 at 14:54 UTC
    Re:Because in your example strong [sic], all the dollars are between brackets.

    I don't see any square brackets in his post, and the string is not inside the angle brackets that form the tags.

      I presumed he meant the < and > characters when he mentioned "square brackets" - otherwise the example doesn't make much sense.

      And considering the string starts with < and ends with >, the "between brackets" condition was ambigious. I just pointed out which meaning I was going to assume. It seems that is the same meaning as you assigned to it.

        my $line = "<ci:Name> Lord: Of The $10Ring$s </ci:Name>"; my $words = ''; if ($line =~ m/<.*>(.*)<\/.*>/) { $words = $1; } print $words;
        How to match all the text outside the angle brackets. Here $10 and $s is not displayed on print. From the text "Lord: Of The $10Ring$s" I have to delete ':' and "$". Please help me to proceed. Thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://768810]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2023-12-11 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (41 votes). Check out past polls.

    Notices?