Style sheet issuewith blank lines - regex

When i opened my style sheet using FTP, it seems lots of blank lines and white spaces.
how do i remove that, please help ..
an example line is here
uploaded css :
h1{
color:#01486d;
font-size:42px;
} /* no blank lines */
when i opened the same style sheet via FTP it is like
h1 {
color:#01486d;
font-size:42px;
}/* lots of white spaces and blank lines */
some one suggest regular expression but i dont know how to use regular expression with dream viewer.
please help
thanks

If you open up Vi/Vim, you can delete blank lines with the following code:
:g/^$/d
and tabs can be deleted with this bit of code:
:g/\t/d
Breakdown:
Hitting escape and then : will get you to the command prompt.
The actual command is g/\t/d
The g searches the entire document
Everything in between the / / is the regex pattern to look for, in this case lines lines that begin (^) with the end of line marker ($) and tabs (\t). The d represents the action to take. In this case, delete the line.

Commands > Apply Source Formatting.

Regular expression to find blank lines:
^$
Regular expression to find multiple blank lines in a row:
[\n]{2,}
You can just delete the first, or replace the second with \n.

Related

Remove any blank or whitespaced lines using regex

I am trying to find and remove any blank or whitespaced lines in OpenOffice document using regex.
Currently I can do it in two steps:
Search for ^$ and replace with nothing.
This will remove any empty lines.
Search for ^\s*$ and replace with nothing.
This will remove any lines which contains only spaces or tabs.
Important note: From my point of view, this 2nd version should also remove any empty lines (as 1st version), but actually it doesn't.
So, there are actually two questions.
For what reason second regex matches only lines with spaces and tabs, but don't match empty lines?
Is there way to combine first and second version to achieve desired result in one step? Here what I tried: ^$|^\s*$ and (^|^\s*)$. But it doesn't work. It matches only whitespaced lines, but not empty ones.
Text for test:
Just for example, I changed spaces to dots
and tabs to dashes.
aa
..........................
-------------------
aaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaa
Desired result:
aa
aaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaa
AltSearch can do this as a single step using a Batch script. In the AltSearch dialog, click on Batch >>. Then Edit the file and paste the following code at the end.
[Name] Remove any blank or whitespaced lines
; Remove any lines which contains only spaces or tabs.
[Find]^\s*$
[Replace]
[Parameters] MsgOff Regular
[Command] ReplaceAll
; Remove any empty lines.
[Find]^$
[Replace]
[Parameters] MsgOff Regular
[Command] ReplaceAll
[End]
Now, save the text file and click Refresh. Finally, click on Remove any blank or whitespaced lines and press Execute.
This produces the desired result and shows a single dialog:
Batch 'Remove any blank or whitespaced lines' is ended.
10 replacements have been done.
Since the title of your question reads like asking for a pure regex (which is why I found it):
\s(?=\s)
Simply replace its matches with nothing - see Regex101 and Regexr.

How do I replace a newline in Atom?

In Atom, If I activate regex mode on the search-and-replace tool, it can find newlines as \n, but when I try to replace them, they're still there.
Is there no way to replace a newline-spanning string in Atom?
Looks like Atom matches newlines as \r\n but behaves inconsistently when replacing just the \n with nothing.
So newlines seem to match \s+ and \r\n, and only "half" of the line-ending matches \n.
If you replace \n with a string, nothing happens to the line-ending, but the string is appended to the next line
If you replace \r with a string, nothing happens at all, but the cursor advances.
It's alittle bit late to answer but i use following term to search and it works with Atom v1.19.7 x64
\r?\n|\r
BR
None of these answers helped me.
What worked for me:
I just added a new line at the end of the file.
Shift + <- (arrow to left)
Ctrl + C
Ctrl + V in the "Replace in current buffer" line
Just copied the new line and pasted it in :D
DELETE INVISIBLE LINE BREAKS IN CODE WITH ATOM
(using the "Find in buffer" function)
(- open your code-file with the Atom-Editor)
Hit cmd(mac)/ctrl(win) + f on your keyboard for activating the Find in buffer function (a little window appears at the bottom atom-screen edge).
Mark your Code in which you want to delete the invisible Line breaks.
Click on the Markup-Mode Button and after that on the Regex-Mode (.*) Button and type into the first field: \n
After that click replace all.
[And Atom will delete all the invisible line breaks indicated by \n (if you use LF-Mode right bottom corner, for CRLF-Mode (very common on windows machines as default) use \r\n) by replacing them with nothing.]
Hope that helps.
Synaikido
You can use backreferencing:
eg. Replace triple blank lines with a single blank line
Find regex: (\r\n){3}
Replace: $1
You can indicate double blank lines with (\r\n){2} ... or any number n of blank lines with (\r\n){n}. And you can omit the $1 and leave replace blank to remove the blank lines altogether.
If you wanted to replace 3 blank lines with two, your replace string can be $1$1 or $1$2 (or even $1$3 ... $3$3 ... $3$2 ... ): $1 just refers to the first round bracketed expression \r\n; $2 with the second (which is the same as the first, so $1$1 replaces the same way as $1$2 because $1 == $2). This generalizes to n blank lines.
The purists will probably not like my solution, but you can also transform the find and replace inputs into a multiline text box by copying content with several line breaks and pasting it into the find/replace inputs. It will work with or without using regex.
For example, you can copy this 3 lines and paste them into both find and replace inputs:
line 1
line 2
line 3
Now that your inputs have the number of lines that you need, you can modify them as you want (and add regex if necessary).
Heh, very weird, Ctrl+Shift+F does not work too!
Workaround: open Atom Settings, then Core Packages->line-ending-selector, scroll to bottom to see tips about command to convert line endings: 'convert-to-LF'.
To convert: Cmd+Shift+P type 'line' and choose 'convert-to-LF' - done!
You could change default option 'Default line ending' from 'OS' to 'LF'.
Also after settings changed your new files will use 'LF'.
prerequisite: activate 'Use Regexp'
in my version of atom (linux, 1.51.0) i used the following code to add 'export ' after a new line
search '\n'
replace '\nexport '
worked like a charm
\r\n didn't match anything

Regular expression to replace two blank lines with one blank line

I'd like to use Xcode's find and replace by regex to remove unnecessary blank lines in my code. In other words I want to replace this:
NSString *helloString = #"Hello";
helloString = [helloString stringByAppendingString:#" World"];
With this:
NSString *helloString = #"Hello";
helloString = [helloString stringByAppendingString:#" World"];
I tried typing control+q return control+q return in the search box (inspired by this answer but it didn't match anything.
What should the regex be?
Copy 2 of the empty lines from your source, press APPLE-OPTION-F to display the searchbar and paste the two lines into the first field.
Then go the second field and enter OPTION-RETURN
Then hit the replace button on the right
Be aware that this matches only lines with the same indendation/spaces/tabs as your copied line. If you need something more flexible better use a texteditor supporting regexen.
As possible regex could be something like "\n.*\n"
I don't know regex very well. I'd just use a simple find and replace of literal strings. Select a blank line by putting your cursor on the last character of a line and pressing shift right-arrow to select the line break. Then bring up a replace dialog and paste 2 blank lines into the find field, and 1 blank line into the replace field.
Xcode doesn't support regex matches across multiple lines, per this mailing-list posting from Apple employee #8 Chris Espinoza.
You could do a two-step process:
Do a regex search like this, to remove whitespace characters from otherwise empty lines:
Find: ^\s+$
Replace: leave blank.
Do a textual (non-regex) search like this, to replace two empty lines with one:
Select two blank lines and go to Edit > Find > Use Selection For Find (Command-E)
Select a single blank line and go to Edit > Find > Use Selection For Replace (Command-Shift-E)
For such tasks and other formatting perhaps you'd like to check uncrustifyX, it's quite easy to use and extensive.

Unwrap text in Sublime Text 2

I'd like to unwrap lines so that I can turn them from lines with hard line-breaks to no line breaks.
Specifically, this means that contiguous runs of lines with non-whitespace should be joined together Essentially, any \n with no whitespace on either side should be replaced with a single space. Other linebreaks shouldn't get touched.
I feel like it ought to be a search-and-replace with a search string something like (?!\n)\n(?!\n) -> , but that doesn't work, as it doesn't match anything.
Is there an ST2 built-in command for this?
any \n with no whitespace on either side
(?<!\s)\n(?!\s)
other linebreaks shouldn't get touched.
(?<!(?:\s|\n))\n(?!\s)
Replace with ''
As #flow mentioned, there are built-ins for that task. Just select the lines you want to join and press Ctrl + J.
And your way should works too. Only you missed a bit. It should be (?<!\n)\n(?!\n)
The following solution works best for text copied from a console log with 80 columns. It only removes \n if the line touches the last column.
Find:
(.{80})\n
Replace:
$1

Remove double spacing

Sometimes, copy pasting code from my email makes everything have an extra blank line.
For example
1: hi
2:
3: hello
4:
Is there a way to target these empty lines with regex and delete them?
I'm using notepad++ with the search(with regex) and replace capability.
Because Notepad++ regex operates only line by line, without a multi-line mode, you can't remove entire lines with regex alone. This is no longer true as of Notepad++ 6.0, which now uses PCRE as its regex engine and allows for multi-line replacements. See this answer for more info.
The TextFX plugin that Notepad++ ships with allows you to remove blank lines without using regex. Just highlight your entire document (Ctrl+A) and do TextFX > TextFX Edit > Delete Blank Lines. If your selection or document begins and/or ends with a blank line though, those lines won't be removed automatically — but removing those is just a matter of:
Ctrl+Home
Del
Ctrl+End
Backspace
To remove double spacing in Notepad++ (I'm using v7.8.4) go to: Edit, Line Operations, Remove Empty Lines.
I don't have notepad++, but the regular expression "^$" (without the quotes) matches only blank lines. Perhaps notepad++ will allow you to replace matches of that regular expression with the empty string, thus removing the blank lines.
Search > Replace...
Search Mode = Extended
Find what : \r\n\r\n
Replace with : \r\n