I want to create a word filter, and I want to store all the words in a database somewhere, probably just some text file. I'm smart enough to get the database from a file into an array, but what I want to do is then to use that array in my regular expressions...
say I have an array of bad words, but I'll make it more simple, we have a string which contains a bad word...
$badword = "badword";
now I want to test my string, $str, for any instinces of $badword. But I don't just want to leave it at that, I want to make sure I catch the silly little "b*a*d w&or-d" instinces. How would I check $str, for $badword with any non word characters between each character.... Basicly I want do do the following, but by using a string rather than literals....
$str =~ /(\bb\W*a\W*d\W*w\W*o\W*r\W*d\b)|badword/;
how could I do that with an array of strings?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.