Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove blank lines: tabs, spaces, (\s) using regex
Sorry for this very simple question.
But I have a lot of trouble tackling this seemingly very simple request:

A string
Copy      Help


The line(s) between between abc and def must be removed IF it contains:
- one or more spaces / one or more ALT+255 chars (nbsp)
- one or more tabs
- one or more ENTERS / SHIFT+ENTERS

It can be a combination of the above

I have tried many regexes containing:
But it constantly creates 1 line (see below) OR it does nothing and thus keeping the original result
Copy      Help

in stead of the desired result:
Copy      Help

How I build the regex:

- I always start the regex by placing the cursor at the beginning by using: ^

Then I follow with

- zero or more spaces: \s*
- zero or more tabs: \t*
- followed at the end by a carriage return and newline: \r\n

I combined that with the previous mentioned: $ ,\w , [] but I end up with all on one line OR no changes at all.
This is really weird for me, because I have solved complexer regexes much easier in QM.
But this simple thing I cannot solve.
(also tried regexes from, but also constantly no result or everything on one line)
Macro Macro2204
Copy      Help
str s="[]one[] [9] two[][]three[] []four"

s.findreplace(" " " ") ;;replace non-break space to simple space. Difficult with regular expression because it is a 2-byte Unicode character.
out s
Works with this test-string. Unless you need to leave empty lines.
Yes this works!!

Forum Jump:

Users browsing this thread: 1 Guest(s)