|
|
|
|
|
|
|
![]() |
#1 |
Remember to rebel against the authorities, kids!
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 |
![]() |
![]() |
![]() |
#2 |
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 |
![]() |
![]() |
![]() |
#3 |
Remember to rebel against the authorities, kids!
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 |
![]() |
![]() |
![]() |
#4 |
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 |
![]() |
![]() |
![]() |
#5 |
a.k.a. Sparky
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 |
![]() |
![]() |
![]() |
#6 |
Remember to rebel against the authorities, kids!
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; } } } # Quote and Quote-like Operators # Regexp Quote-Like Operators & using q somewhere may be the answer?
__________________
XXX Porno Hardcore |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | Rate This Thread |
|
|