in reply to Re: regex needed to remove parts of SQL
in thread regex needed to remove parts of SQL

great!!, thats what I need.
One last thing; what if I don't want to use $1 ? Should I split it in 2 expressions
$sql =~ s/(?:SELECT)\s*[^,]*?\s+as/SELECT/gi ; $sql =~ s/,\s*[^,]*?\s+as/,/gi ;
This works, except I don't understan why (?: .... ) is not working (I don't want to replace the word SELECT)

LuCa

Replies are listed 'Best First'.
Re^3: regex needed to remove parts of SQL
by mayaTheCat (Scribe) on Sep 12, 2007 at 11:15 UTC
    In that case,
    $sql =~ s/(?<=select)\s*[^,]*?\s+as//gi ; $sql =~ s/(?<=,)\s*[^,]*?\s+as//gi ;
    Looks like the problem was that (?:) is non-capturing grouping. It stills eats up the characters. What you need is lookbehind (?<=).

    I also tried

    $sql =~ s/(?<=select|,)\s*[^,]*?\s+as//gi ;
    But the interpreter refused and said
    Variable length lookbehind not implemented in regex
    So, it looks like you have to have two regexes if you do not want to use $1.

    Oguz

    ---------------------------------
    life is ... $mutation = sub { $_[0] =~ s/(.)/rand()<0.1?1-$1:$1/ge };

      what about this
      $sql =~ s/((?<=select)|(?<=,))\s*[^,]*?\s+as//gi ;
      I couldn't have done this without your help!!

      thnx
      LuCa