Reputation: 55273
I have a string like this:
"Product DescriptionThe Signature Series treatment makes the strategy guide a COLLECTIBLE ITEM for StarCraft II fans. Single-player CAMPAIGN WALKTHROUGH covers all possible mission branches, including bonus objectives throughout the campaign. Exclusive MAPS found only in the official guide, show locations of units,... \n\n\n\n\n\n\nRead More\n"
How can I use regex the .text[/(...)/]
to remove what's after the ...
so that it outputs like below?
"Product DescriptionThe Signature Series treatment makes the strategy guide a COLLECTIBLE ITEM for StarCraft II fans. Single-player CAMPAIGN WALKTHROUGH covers all possible mission branches, including bonus objectives throughout the campaign. Exclusive MAPS found only in the official guide, show locations of units,..."
Upvotes: 1
Views: 904
Reputation: 11487
You can also do
/(^.*)(\.\.\..*)/.match(string).captures[0]
Upvotes: 0
Reputation: 71538
You should be able to use the split method, something like that (I'm not that familiar with Ruby).
arr = text.split("...") #=> text before '...' and text after '...'
arr[0] #=> text before '...'
Upvotes: 2
Reputation: 33908
No need to use lookarounds, you could simply do something like:
string.sub(/\.{3}.*/s, "...")
Upvotes: 1
Reputation: 168101
You need to escape the period.
string.sub(/(?<=\.\.\.).*/m, "")
or
string[/.*\.\.\./m]
Upvotes: 3