我希望能够说出
if target.hostname == string.match(/attacker./)
并匹配任何具有字符串的主机名,例如“attacker1”,“attacker2”等。
我似乎无法找到coffeescript中的等价物。也许有人知道这个正则表达式语法?
更新:
我使用了此处的示例:http://www.elijahmanor.com/regular-expressions-in-coffeescript-are-awesome/
创建此正则表达式:
attackerPattern = /// ^ # begin of line
/attacker/ # the word "attacker"
([0-9]+) # followed by a number
\. # followed by a dot
([a-zA-Z]+) # followed by one or more letters
\. # followed by a dot
([/com/]) # followed by a com
///i # end of line and ignore case
因为我想抓一些说“attacker1.node.com”或“attacker2.node.com”等的东西。
我似乎能够用这种模式来捕捉这个:
attackerPattern = /attacker/i
也许这就足够了(因为它不会关心主机名的其余部分),但我更希望它更具体的例子,它需要在“attacker1”之后拥有.someword.com。有什么建议吗?