Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Find string match

by ddragosa (Acolyte)
on Feb 23, 2010 at 12:45 UTC ( [id://824850]=perlquestion: print w/replies, xml ) Need Help??

ddragosa has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I have a question about searching a string.

For example I have the following string:

insert into table1 ( v1, v2 , v3) values ( v1, v2, v3)

How can I extract only what's between "into" and the first "(" ?. The name of the table?

Thank you.

Replies are listed 'Best First'.
Re: Find string match
by Ratazong (Monsignor) on Feb 23, 2010 at 12:52 UTC
      Not quite
      ($tablename) = $str=~/\binto\s+([\S]+)/; Updated: on foot of cdarke's observations below

      print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
        Not quite
        The match returns 1 (true). Maybe you are thinking of s?
        $str=~/\binto\s+(\S+)/; my $tablename = $1;
        [^\s] is better written as \S
        Or maybe:
        my $tablename = ($str=~/\binto\s+([^\s]+)/)[0];

      Thanks. I forget about the "?" after the (.*)

Re: Find string match
by bobf (Monsignor) on Feb 24, 2010 at 04:53 UTC

    If you are going to do anything tricky or if you need more flexibility, you might want to consider using SQL::Statement::Structure instead.

Re: Find string match
by 7stud (Deacon) on Feb 23, 2010 at 14:48 UTC
    use strict; use warnings; use 5.010; my $query = 'insert into table1 ( v1, v2 , v3) values ( v1, v2, v3)'; my @pieces = split ' ', $query, 4; say "-->$pieces[2]<---"; --output:-- -->table1<---

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-20 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found