2020-11-30

How can I get the boundaries of a regular expression?

Lets say I have a string that I need to split into an array based on a pattern. Many language split methods will remove the things matched by the pattern causing a split of a string

testtestt

on the regular expression

.{2}

ending up with a result of

t

This is not the result I wanted so how can I use a regular expression only to capture the borders of what is matched with the same scenario above being matched as

te|st|te|st|t

and as a result being split into an array of

['te','st','te','st','t']

?

Note: This is not language specific and the ideal answer would be a regular expression instead of a piece of code exclusive to certain languages.



from Recent Questions - Stack Overflow https://ift.tt/2Jby6lv
https://ift.tt/eA8V8J

1 comment:

  1. This blog resolved all my queries I had in my mind. Really helpful and supportive subject matter written in all the points. Hard to find such kind of blogs as descriptive and accountable to your doubts.How to get rid of Discord Javascript Error [100% SOLVE ISSUE]

    ReplyDelete