Gossamer Forum
Home : General : Perl Programming :

Regular Expression Question !!!

Quote Reply
Regular Expression Question !!!
 
Hi Friends !!!

I just want to know the regular expression which should return only "EMPNO=","DEPTNO=","JOB=" from the following query with set of placeholder values,

"select * from EMP where EMPNO=&eno and DEPTNO=&dno and JOB=&job".

The query may be dynamic,like it may contain even a single placeholder value like,

"select * from EMP where EMPNO=&eno"

I just need a general regular expression that should return the "EMPNO=","DEPTNO=","JOB=" variables from the query. [key point here is : take the variable which is residing before "&" and stop obtaining it when a space comes in. like "where EMPNO=&eno" before "&" it contains EMPNO=]


Could anyone please help me out in this ?

Thanks,
Warm Regards,
Saravanan
Quote Reply
Re: [slg_saravanan] Regular Expression Question !!! In reply to
Mmm.. guess something like this wouldn't work?

$val =~ m|EMPNO=(.*?)\s+|

?

The problem really, is the fact they are not quoted =) That would make it a bit easier Tongue

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Regular Expression Question !!! In reply to


$string = "select * from EMP where EMPNO=&eno and DEPTNO=&dno and JOB=
+&job";

@arr = split('\s+',$string);
foreach $i (@arr)
{
if($i =~ /\&/g)
{
@arr1 = split('&',$i);
print $arr1[0]."\n";
}
}

ABove one works like KING !!! Thanks a ton Andy !! Smile

Quote Reply
Re: [slg_saravanan] Regular Expression Question !!! In reply to
Code:
my @ph = $string =~ /[A-Z]+=&([^ ]+)/g;

Last edited by:

Wychwood: Jun 21, 2007, 12:03 PM