匹配子字符串但不是异常子字符串

时间:2013-07-05 06:14:39

标签: ruby regex

我有像:

这样的字符串
new_account_notification
updated_account_notification
reactivated_account_notification
updated_billing_info_notification

我想这样匹配这些字符串:

  • 应包含account
  • 但不应包含reactivated_account
  • 或应包含billing_info

请建议正则表达式来满足这些条件。

1 个答案:

答案 0 :(得分:6)

尝试这种模式:

(?<!reactivated_)account|billing_info

(?<!...)是一个负面的背后(希望你的正则表达式支持它)

|代表OR

相关问题