Matt Burrough
Matt Burrough

Reputation: 25

How can I match a regex on a substring of the pattern?

I'm looking for an efficient way to get a regex to greedily match any strings that are a sequential substrings of my pattern. For example, given the pattern "qwerty", I'd like it to match:

I don't want it to match non-sequential texts, or patterns that don't start at the beginning, such as:

Upvotes: 1

Views: 53

Answers (1)

Aminah Nuraini
Aminah Nuraini

Reputation: 19206

Easy! You can use ? for an optional occurrence.

^q(w(e(r(ty?)?)?)?)?

Upvotes: 2

Related Questions