asdf
asdf

Reputation: 667

Capturing a group of strings that has a specific regex

In my case I want to capture a group of strings that contain a specific number of consecutive characters.

I know I can find that by writing something like:

/('characterHere')\1\1\1\1.../ <- as many times as I want the consecutive string to have the character

which works fine, I can find that string of the consecutive characters in my strings.

My question is once I find a string with that consecutive character I am interested in how can I grab the entire string regardless of the rest of its contents?

ex) Sample strings:

xxxxxxxxyyyxxxx
xxxxxyyyxxxxxx
xyxyxyxyyyxxxx

Notice those three strings had three consecutive y's regardless of the rest of the string.

So:

 /(y)\1\1/ can find the three y's in a row,
 but I cant grab the entire string (which is what I want).

Upvotes: 0

Views: 66

Answers (2)

Bohemian
Bohemian

Reputation: 425013

It looks like you want just this:

.*y{3}.*

Upvotes: 0

vks
vks

Reputation: 67968

(?=.*?y{3})^.*$

Try this.See demo.

http://regex101.com/r/cH8vN2/2

Upvotes: 1

Related Questions