CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Matching non word characters

 



d1zz13
User

Apr 24, 2007, 3:03 AM

Post #1 of 3 (3791 views)
Matching non word characters Can't Post

I'm trying to validade some SQL but I'm having an issue matching non-word characters.

I have a file that contains table names that I won't allow users to modify and I'm opening this and looping through each row.

Here's what I have:


Code
# Open the file containing the list of bad tables 
open(FH, "$tablelist") || die ("Unable to open $tablelist: $!\n");
@tables = <FH>;
close(FH);

# Open the script that's being checked
open(FH, "$sqlfile") || die ("Unable to open $sqlfile: $!\n");
while ($l = <FH>){
chomp $l;
# Check for any of the invalid tables
foreach (@tables){
chomp;
if ($l =~ /(insert\s+into|delete\s+from|update)\s+\Q$_\E\W/i){
print "\n$sqlfile failed integrity check, keyword matched at line $. ($_)\n\n";
exit(1);
}
}
}
print "\n$sqlfile passed integrity check\n";
close(FH);


Lets assume my table file looks like this:

Code
object 
object_type


If my code is like this then it seems to work fine

Code
UPDATE object SET column1 = column2


but if it's like this, it doesn't

Code
UPDATE object 
SET column1 = column2


so I assume that a newline character is not included as either a word character or a non-word character. I'm really stumped on this one. Any help would be appreciated.

Regards
Rich

If it aint broke then don't try to fix it


osmodius
Novice

Apr 24, 2007, 4:05 AM

Post #2 of 3 (3789 views)
Re: [d1zz13] Matching non word characters [In reply to] Can't Post

You can match a newline with \n.


Need some real-time help? Shove admin@ub3r.net on yer MSN.


d1zz13
User

Apr 24, 2007, 4:57 AM

Post #3 of 3 (3788 views)
Re: [osmodius] Matching non word characters [In reply to] Can't Post

I've figured it out, I was being a muppet. There wasn't a newline there, the line had been chomped.

I've settled for this:


Code
if ($l =~ /(?:insert\s+into|delete\s+from|update)\s+\Q$_\E(?:\W|$)/i){


Can anyone see any issues with this?

Regards
Rich

If it aint broke then don't try to fix it

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives