In AS3, I have created a nice swear filter routine that imports a list of regular expressions for swear words and combines them into a single regular expression. However, one bit I’m having problem over are football teams, namely ARSENAL and SCUNTHORPE.
Is there a way in a regular expression to block the swearwords unless they complete the words to be the above? I tried the following with ARSENAL but it didn’t work properly:
/arse[^(nal)]/gi
The problem is that I cannot parenthesise the letters “nal” because it sees the parentheses as characters rather than a block. It appears to expect at least one extra character after “arse” in order to work. Can I make it so that it will allow one but not the other? How can I group letters together and say “not”?
EDIT: I found elsewhere on Stack some talk of “negative lookahead”s but didn’t quite get how I could do that for these two use cases… Any ideas?
I don’t know about Actionscript specifically but in most Regex engines you can use
negative lookahead:
?!negative lookbehind:
?<!So for Arsenal:
And Scunthorp or sHAPPYhorp:
And Scunthorp will be similar to sHAPPYhorp, left as an assignment for the reader.