Suppose you have a string (e.g. needle ). Its 19 continuous substrings:
needle needl eedle need eedl edle nee eed edl dle ne ee ed dl le nedl
If I were to create a regular expression to match, in a haystack, any of the substrings that I could just do:
/(needle|needl|eedle|need|eedl|edle|nee|eed|edl|dle|ne|ee|ed|dl|le|n|e|d|l)/
but it doesnβt look very elegant. Is there a better way to create a regular expression that will greedily match any of the substrings of a given string?
Besides, if I set another restriction, I wanted to combine only substrings that exceed the threshold value, for example. for substrings of at least 3 characters:
/(needle|needl|eedle|need|eedl|edle|nee|eed|edl|dle)/
Note: I did not specifically mention any particular regular expression dialect. Indicate which one you use in your answer.
string substring regex
CAFxX
source share