Importing a regular expression from a file
Posted by meanroy (meanroy), 7 August 2006I have a script which is used to remove spam from a Wiki.
The collection of spam phrases (and Spammer urls)has grown unwieldy.
Here's a 'snippit' to show how I use the regex.
I've not been able to figure out how to keep the banned phrases and URL's in a file and import them.
I found this reference from Perl Regular Expressions - detailed manual but it doesn't seem quite what I need.
I may be missing some trivial way to do this but I can't seem to find it.
Do you have any suggestion?
It looks like the perlfaq6 manpage may help though I'm having trouble with putting more than one expression in the file.
only does one line. I'll keep hacking but if you could clarify this I'd appreciate it.
Posted by admin (Graham Ellis), 8 August 2006I think you're getting there. I suggest 1 RE per line, read in and chomp each in turn.
Posted by meanroy (meanroy), 8 August 2006Yes, that seems to work but at the expense of using a lot of time reading the file. (relatively)
Maybe I should bring the file into a Hash and sequence through the Hash or into an array of strings and step through the array?
- edit -
I've gone back to the "Owl" book, Mastering Regular Expressions, since after skipping lightly past this particular little problem, I'm up against more regex madness.
After I've figured out things a bit I'll post some code. (I hope!)
Posted by meanroy (meanroy), 10 August 2006I've been able to get a file of regex to work somewhat, though I have more to do, but can't seem to get past this pecularity:
I expected to see only two elements printed.
Instead I find:
I've spent a lot of time messing with this and searching everywhere, trying to figure it out.
What the heck is going on?
"split produces a list of the things either side of the match. If the match occurs at the very start of the data, then a null field is produced. This is Item0."
I confess I didn't figure it out myself, asked on perlmonks.
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho