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


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
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