I'm trying to find a regex that will be capable of adding a trailing space at the end of every segment in a file in Studio. Does anyone know of a regular expression that would do the trick? Thanks!
I'm trying to find a regex that will be capable of adding a trailing space at the end of every segment in a file in Studio. Does anyone know of a regular expression that would do the trick? Thanks!
Find what: ^(.*)$
Replace with: $1#
where # should be replaced with a space (blank)
should work.
Caveat: For some reason, Studio 2019 Find/Replace handles the first segment incorrectly and so must be corrected manually.
If you want to avoid having more than one space at the end of the segment in case there is already one, try this (without the quotes):
I also tried to search with a negative lookbehind "(?<! )$", but it does not seem to work in Studio (but works fine in Notepad++), unless I am missing something.
Yes, this does work, thank you very much Anthony!
Thank you very much for this suggestion, Raphaël. I didn't need it this time, but I have copied it for future reference!
The variant to skip any multiple spaces at the end of the string
^(.*?)\s*$
A more efficient and simpler solution:
(\S)$
with the above Replace string
This adds a space to be last character of the segment, unless it is already a whitespace
The reverse situation, namely to remove all trailing spaces, can be matched with the regex
(\s*)$
with a null (empty) Replace string