JR Tan
JR Tan

Reputation: 1725

Regex match all words including slash

I would like to remove all words behind the number.

12 - Balloon Cool
1 - I would like to sleep
541 - Sleep is for weak/sheep

Currently I 'm using this regex to replace them with empty

/ - (\w+( +\w+)*)/

It managed to filter some but not for the string with slash.

12
1
541sheep

Upvotes: 1

Views: 190

Answers (2)

anubhava
anubhava

Reputation: 784948

To remove any thing after space-hyphen-space you can just use:

/ - .*$/m

RegEx Demo

Upvotes: 2

JimmyJames
JimmyJames

Reputation: 1403

I would use something like this:

Search: ^(\d+)\s+-.*?

Replace: $1

Upvotes: 0

Related Questions