I have a little function that reads a file and extracts quotes to add to a pool of quotes that might be randomly placed at the bottom of a web page that I maintain for a small club. I have discovered that some of the quotes are a little 'off-color', that is, they could be offensive, and this page is hosted on a student webserver. I can only imagine the uproar if the wrong person read the wrong quote, and took it out of context...
So anyway, I wrote a very simple little regex that skips the most inflamitory quotes by doing alternation:
This works fine, but I am looking to learn a lesson here about a better way to do things... What I would like to be able to do is have a list of "bad words", and write a regex that would skip to the next if the string contained any one of the list members. It seems like I'm going about it the wrong way here, since I have to go in and add |foo|bar|baz... to the match every time I spot another word someone doesn't like.foreach (<FH>){ if(/^[0000-9999](.+)/){ next if /smurf|fork/; push( @witty_quotes, substr( $_, 5) ); } else { next }; }
So I am looking for a good way to test to see if a string contains a match for any member of a list.
I have been trying some different things on my own, but I would really like to see how others might go about this problem. Thanks!
In reply to test if a string contains a list member by mull
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |