String to check:
As it turns out, our potential shipmates are extremely superstitious. As such, we do not want anyone to enter certain words in their comments.
Requirements:
1. Let‘s start checking for bad words within a sentence. We can begin with ‘sink‘
as our first bad word. We will want to make sure this word is by itself and not part of a larger word.
/\bsink\b/gim
2. Looking good, but there are more bad words we need to account for. Let‘s also check for ‘wreck‘
.
/\b(sink|wreck)\b/gim
3. Almost finished. Our final bad word to match is ‘disaster‘
.
/\b(sink|wreck|disaster)\b/gim
-------------------------------------
/http(s)?:\/\/(www\.)?twitter(\.com|\.org)\/codeschool/gm
[Regex Expression] Confirmative -- World bundry
原文:http://www.cnblogs.com/Answer1215/p/5245989.html