-2

I'm trying to write an expression in Regex where I want to match at least n of the items in my list. I'm trying to make a filter where I filter out users who have triggered at least three out of seven actions.

Let's say I have a list of actions:

abc
def
ghi
jkl
mno
pqr
stu

How can I write an expression in Regex where I can filter out users who have triggered three or more of those actions?

I have a follow up question to my question above.I am now wanting to take it a step further. I want to make a filter for all users who have visited three or more webpages on my site that contains a specific number sequence in the url. By instance, users who have visited three or more of the webpages:

www.website.com/123  
www.website.com/234 
www.website.com/345
www.website.com/456  
www.website.com/567  
www.website.com/678
www.website.com/789

Any help is greatly appreciated!

AndréG
  • 1
  • 2
  • 1) What is "match at least three (or more) of those words?" Give an actual example. 2) What have you tried and where does it fail? Please [edit your question](http://stackoverflow.com/posts/26732358/edit) – Jan Doggen Nov 04 '14 at 10:09
  • Unclear, could you add some more explanation? – Avinash Raj Nov 04 '14 at 10:10

1 Answers1

2

Steps:

  • \b(abc|def|pqr|stu)\b - create group with alternative words.
  • {3,} - specify min count.

Regex:

(?:\b(abc|def|pqr|stu)\b.*){3,}

regex demo

Sergii Lagutin
  • 10,561
  • 1
  • 34
  • 43