Reputation: 2218
Right now I am using .split(/(?<=[.])/)
which splits keeps the period.
string = "Going home. See you soon."
=> ["Going home.", "See you soon."]
But what I need is to split on and keep ". "
Upvotes: 1
Views: 232
Reputation: 6121
If it is that straight forward, why you need a regex, just provide the string to split on as
"Going home. See you soon.".split('. ').map{ |s| "#{s}." }
Upvotes: 1
Reputation: 369034
Using look-behind assertion, you can match space () following
.
((?<=\.)
):
string = "Going home. See you soon."
string.split(/(?<=\.) /)
=> ["Going home.", "See you soon."]
Upvotes: 3