| ||||||||||||
| ||||||||||||
Importing a regular expression from a file Posted by meanroy (meanroy), 7 August 2006 I 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. Code:
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. Quote:
I may be missing some trivial way to do this but I can't seem to find it. Do you have any suggestion? Roy. =========== Oopsie... It looks like the perlfaq6 manpage may help though I'm having trouble with putting more than one expression in the file. The example Code:
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 2006 I think you're getting there. I suggest 1 RE per line, read in and chomp each in turn.Posted by meanroy (meanroy), 8 August 2006 Yes, 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? Roy - 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 2006 I'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:Quote:
I expected to see only two elements printed. Instead I find: Quote:
I've spent a lot of time messing with this and searching everywhere, trying to figure it out. What the heck is going on? Roy Oh Duh! "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. This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| |||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |