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!
Spaces can be found simply by putting a space character in your regex. Whitespace can be found with \s . If you want to find whitespace between words, use the \b word boundary marker.
\W means "non-word characters", the inverse of \w , so it will match spaces as well.
You can easily trim unnecessary whitespace from the start and the end of a string or the lines in a text file by doing a regex search-and-replace. Search for ^[ \t]+ and replace with nothing to delete leading whitespace (spaces and tabs). Search for [ \t]+$ to trim trailing whitespace.
Regex uses backslash ( \ ) for two purposes: for metacharacters such as \d (digit), \D (non-digit), \s (space), \S (non-space), \w (word), \W (non-word). to escape special regex characters, e.g., \. for . , \+ for + , \* for * , \? for ? .
[ ](?=[^ ]+$)
You can try this.Replace by ,
.See demo.
https://regex101.com/r/oL9kE8/17
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With