Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Tricky Perl Regurlar

Expand Messages
  • ramprasad@netcore.co.in
    Hi I had made a mistake in giving the test string. I cannot use the map expression because there may be some other characters which I dont want before the 0,
    Message 1 of 2 , Nov 30, 2001
    • 0 Attachment
      Hi
      I had made a mistake in giving the test string. I cannot use the map
      expression because there may be some other characters which I dont
      want before the 0,
      eg.
      0,'hello\'a' ddd 0,'abc',0,'def'

      sorry for before



      --- In perl-beginner@y..., "Charles K. Clarkson" <cclarkson@h...>
      wrote:
      > "Ramprasad A Padmanabhan" <ramprasad@n...>
      >
      > : Hi
      > : I have got a string like this
      > : 0,'hello world\'s people' 0,'It is for me'
      0,'It\'s not
      > for me'
      > :
      > : Every string enclosed by quotes has a 0,
      before it .
      > :
      > : I want a regular expression which will create an array of all
      strings
      > within quotes
      > :
      > : I tried like this
      > : $str=~s/0,\'(.*?)\'/{ push @allvals,$1}/ge;
      > : this works fine but fails if the string itself has a quote
      sign
      > :
      > : I have written a work around ( and am very unhappy about
      it )
      > :
      > : Anyone can give me a better Idea
      >
      >
      > my @all_vals = map {s/\s+$//; substr $_, 1, -1} $str =~
      /0,([^0]*)/g;
      >
      > Or for the map impaired:
      >
      > my @all_vals = $str =~ /0,([^0]*)/g;
      > foreach (@all_vals) {
      > s/\s+$//; # rid of us trailing spaces
      > $_ = substr $_, 1, -1; # lop off the first and last '
      > }
      >
      >
      >
      > HTH,
      > Charles K. Clarkson
      > Clarkson Energy Homes, Inc.
      >
      >
      > Get the facts first. You can distort them later. - Mark Twain
    Your message has been successfully submitted and would be delivered to recipients shortly.