2013-07-05 46 views
3

我有这样的字符串:匹配字符串,但不是一个特殊的子

new_account_notification 
updated_account_notification 
reactivated_account_notification 
updated_billing_info_notification 

我想匹配这些字符串作为这样的:

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

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

+0

哪个正则表达式的味道你使用? – Stephan

+0

@Alex:我正在尝试使用我的Ruby程序。 – Vishal

回答

6

尝试这种模式:

(?<!reactivated_)account|billing_info 

(?<!...)是负回顾后(希望你的正则表达式的味道支持它)

|代表或

+1

这也会匹配,如果没有'帐户' – Anirudha

+0

@Anirudh:是的,但我相信这是他想要的。 –

+0

@Anirudh:没有。我试图在'test_notification'字符串上匹配它。 – Vishal

相关问题