Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Manipulation of output of multiple parse line.

by kennethk (Abbot)
on Jun 12, 2013 at 14:23 UTC ( #1038488=note: print w/replies, xml ) Need Help??

in reply to Manipulation of output of multiple parse line.

To use regular expressions to chop leading spaces, use the ^ anchor to specify 'start at the beginning'. Also, rather than the g modifier (since you really only need to substitute once), use + to indicate 'one or more'. I prefer the character class \s to an explicit space (' '), but YMMV.
YAPE::Regex::Explain describes this as:
The regular expression: (?-imsx:^\s+) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- \s+ whitespace (\n, \r, \t, \f, and " ") (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
See Metacharacters and Quantifiers in perlre.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2016-10-28 12:25 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (383 votes). Check out past polls.