I want to capture a substring of a string, choosing the number of characters, but if any word is cut, then until the last space is received.
As an example, if this is text:
"This is an example of lorem ipsum text, etc."
12 characters would give "This is e." In this case, the last word is cut, so the result should be "This."
Is it possible to do this with regular expressions?
source
share