A
A
a--x2019-05-07 22:22:48
Regular Expressions
a--x, 2019-05-07 22:22:48

How can regexp find all occurrences of a substring if some overlap with those already found?

There is a text. I want to find all combinations of two words
that are next to each other and are separated by something (a space), and that the second word is 3 characters long or more.
I wrote down the regular expression
\S+\W+?\S{3,}
I check: https://regex101.com/r/m8GiSB/1
For the text "Toaster" is a highly specialized question and answer service, ..."
I get entries: 1. " Toaster
" is
2. a highly specialized service
3. questions and answers,
...
But I also need these:
4. it is a highly specialized
5. question service
and return to the previous space? To find all combinations of standing two words in a row.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dollar, 2019-05-07
@dollar

What programming language?
For example, JS has an exec function that iterates, and in the body of the loop, you can change the current search position, which is stored in the lastIndex variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question