Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2006-10-11, 10:21 PM   #1
Jeremy
Remember to rebel against the authorities, kids!
 
Jeremy's Avatar
 
Join Date: Aug 2003
Location: AU
Posts: 406
Controlling REGEX in Perl?

Gotta q for the perl gurus who are much much wiser than me.

When you read data into an array, if that data has a REGEX character in it, PERL handily recognises it and acts on it if you want to compare that array against another array of data.

EG if the first array has "foo.*bar" then if the second array has "foofumbar" and "foo.*bar" in it PERL will find them.....

BUT what if you actually wanted to search that second list for "foo.*bar" literally and ignore "foofumbar" completely, how do you do that?
__________________
XXX Porno Hardcore
Jeremy is offline   Reply With Quote
Old 2006-10-11, 11:24 PM   #2
JK
Well you know boys, a nuclear reactor is a lot like women. You just have to read the manual and press the right button
 
Join Date: Nov 2003
Posts: 157
I'm not a guru mate, but I think all you'd need to do is escape the 'special' characters. foo.*bar literally should just be foo\.\*bar
__________________
To alcohol! The cause of, and solution to, all of life’s problems
JK is offline   Reply With Quote
Old 2006-10-11, 11:40 PM   #3
Jeremy
Remember to rebel against the authorities, kids!
 
Jeremy's Avatar
 
Join Date: Aug 2003
Location: AU
Posts: 406
That'd work mate... but it's a bit of a long way round - especially if you don't quite know what you're going to find in the data you're analysing.

EG, when I've analysed link descriptions, I've run into problems where descriptions have things like: "?" or "+" or even ":-)" smilies have caused the script to grind to a halt..... so it needs to be flexible enough to deal with whatever gets thrown it's way.

I'm sure that the answer's staring me in the face in PERLOP, but I'll be buggered if I can spot it!
__________________
XXX Porno Hardcore
Jeremy is offline   Reply With Quote
Old 2006-10-12, 12:04 AM   #4
JK
Well you know boys, a nuclear reactor is a lot like women. You just have to read the manual and press the right button
 
Join Date: Nov 2003
Posts: 157
Aaah ok, I see where you're coming from now mate. Sorry I can't be of help.
__________________
To alcohol! The cause of, and solution to, all of life’s problems
JK is offline   Reply With Quote
Old 2006-10-12, 08:59 AM   #5
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
how about the index function?

Code:
#!/usr/bin/perl

$string1 = "asdf asdf foofumbar asdf asdf";
$string2 = "asdf asdf foo.*bar asdf asdf";
$find = "foo.*bar";

print "string1: " . index($string1,$find) . "\n";
print "string2: " . index($string2,$find) . "\n";
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2006-10-12, 09:10 PM   #6
Jeremy
Remember to rebel against the authorities, kids!
 
Jeremy's Avatar
 
Join Date: Aug 2003
Location: AU
Posts: 406
Thanks for that Chris - will look into it.

This is actually the way that I'm using it at the moment:

Obviously it's just an example, but I've seen odd behaviour when data from either array has regex or pattern type characters in them.

Code:
#!/usr/bin/perl -w


## This Array is the orginal data to be searched:
## Data in here may have regex / pattern characters.
open (FH, "$WorkingDir/FILENAME");
while (<FH>)
	{
		chomp $_;
		push(@Data_Array, "$_");
	}
close (FH);


## This Array contains the things we want to look for 
## in the Data_Array:
## Data in here may have regex / pattern characters.

open (FH2, "$WorkingDir/FILENAME");
while (<FH2>)
	{
		chomp $_;
		push(@Look_For_Array, "$_");
	}
close (FH2);

foreach $Data_Array(@Data_Array)
{
	foreach $Look_For_Array(@Look_For_Array)
	{
		if ($Data_Array =~ /$Look_For_Array/i)
		{
			$Data_Array =~ s/$Look_For_Array/$Something_Else/gmi;
		}
	}
}
Maybe I should be looking in Perl OP at:
# Quote and Quote-like Operators
# Regexp Quote-Like Operators

& using q somewhere may be the answer?
__________________
XXX Porno Hardcore
Jeremy is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:23 AM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc