Reputation: 932
I'm trying to find the space before the last word of a string.
For example, for
Bob Jane
I would want to find the space right before Jane. I am trying to do a find and replace all to make that become a comma. Thus, the final result would be
Bob ,Jane
I'm only doing this in a text editor (using Sublime) so I'm not using a programming language. Thank you!
Upvotes: 5
Views: 2812
Reputation: 67978
[ ](?=[^ ]+$)
You can try this.Replace by ,
.See demo.
https://regex101.com/r/oL9kE8/17
Upvotes: 5
Reputation: 174766
Find What:
(\S+ *)$
REplacement string:
,\1
If you want to add a comma after to the space which exists before the last word then try the below regex.
(?<= )(\S+ *)$
Replacement string:
,\1
Upvotes: 1