Using regex to trim trailing white space

Swifty

My editor EditpadPro allows me to create syntax colouring schemes. The scheme I'm writing includes comments which span "--" to end of a line.

I'd like a regex which starts from the "--" but which stops at the last non-blank character. I cannot use "replace" as I'm just entering the regex, not using it myself.

So, if the text in my line of code is:

X=1 -- This is a comment with trailing blanks

Then the regex would return:

-- This is a comment with trailing blanks

The reason for this is that I can highlight the trailing blank space as waste space.

melpomene

I'm not familiar with EditPad Pro, but

--(?:.*\S)?

might work.

The idea is to match --, followed by 0 or more of any (non-newline) character (.), followed by a non-space character (\S). Because the "0 or more" part is greedy, it will try to match as much of the line as possible, thus making \S match the last non-blank character of the line.

The ? makes the whole thing after -- optional. This is because you might have a comment without a non-space character in it:

--

This should still be matched as a comment, but not any trailing spaces (if any).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Regex to trim trailing space and new line

Regex to extract numbers and trailing letter or white space

Automatically Trim Trailing White Space for properties in Props file loaded into Spring

Sublime Text 2: Trim trailing white space on demand

How can I trim leading and trailing white space?

Remove white space from string without using trim method?

Skip leading and trailing white space

Trim white space in table cell

How to ignore white space in string using regex?

How to trim leading and trailing white spaces of a string?

Jmeter Regex trim space

trim() leaves a single trailing and leading space

Regex ignore white space

Remove trailing white space from elements in a list

How to create folder without trailing white space?

Is trailing white space is forbidden in s-expression?

Ruby #match? misses trailing white space

How to eliminate the trailing white space after an ArrayList?

how to trim white space in array in php

How to trim white space for every element in JQ?

Trim all white space from string JavaScript

Postgres: Trim white space from array values

Trim extra white space within column

Trim() and Replace(" ", "") not removing white space in C#

How to locate and click the element when the innerText contains leading and trailing white-space characters using Selenium and Python

remove white space between specific characters using regex in python

Extra white space when using regex in Scanner.useDelimiter()

Remove every white space between tags using regex only

How to trim leading and trailing white-spaces by a single command?