Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

RE: Re: Regexp glitch while parsing record in CSV

by greenhorn (Sexton)
on Jul 17, 2000 at 04:10 UTC ( #22824=note: print w/replies, xml ) Need Help??


in reply to Re: Regexp glitch while parsing record in CSV
in thread Regexp glitch while parsing record in CSV

<kbd>> m#(?:[^,]*,\s*){3}(.*?)\s*,#</kbd>

This worked, thanks--and taught me a couple of things about regular expressions that I'd seen in several of the books but hadn't yet understood.

Still perplexed by the failure of the other regexp. Even though<kbd> [^,]+ </kbd>does indeed include spaces, I'm perplexed by why the<kbd> \s* </kbd>preceding and following it fail to catch spaces when they exist in those locations in the string.<kbd> \s* </kbd>does catch them when it is used this way:

<kbd>split /\s*,\s*/ , $_</kbd>

Thanks again.

  • Comment on RE: Re: Regexp glitch while parsing record in CSV

Replies are listed 'Best First'.
(chromatic) RE: RE: Re: Regexp glitch while parsing record in CSV
by chromatic (Archbishop) on Jul 17, 2000 at 21:20 UTC
    The asterisk can be a little tricky. It means, match zero or more of the preceding. In a construct like \s*[^,]+\s*, the character class does match the spaces and the comma. The + is greedy, too.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2022-09-29 21:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (125 votes). Check out past polls.

    Notices?