Notepad ++ (REGEX); Invert Selection,
The following 2 different codes, it works very nicely. :)
now I want to combine these two different code!
\bhttps?:[^)''"\s]+.(?:jpg|jpeg|gif|png)
https://codereview.stackexchange.com/questions/20126/regex-to-get-all-image-links
^((?!hello).)*$
notepad++ Inverse Regex replace (all but string)
So you want to find and remove all rows not containing an image URL specified by the regular expression \bhttps?:[^)''"\s]+.(?:jpg|jpeg|gif|png)?
You can combine the two regular expressions like this:
^((?!\bhttps?:[^)''"\s]+.(?:jpg|jpeg|gif|png)).)*$
If you replace the lines with an empty string, you can then use the menu option "Edit - Line Operations - Remove Empty Lines" to remove the empty lines.
Another option is to use bookmarks:
Select the "Mark" tab from the replace dialog and enter your first regular expression (the one that finds the image URL's). Check "Bookmark lines" and click "Mark all". From the menu, first select "Search - Bookmark - Inverse Bookmark", and then "Search - Bookmark - Remove Bookmarked lines" to remove the lines.
Related
I have csv file where each record is one line. Problem is that sometimes one cell have few lines. For example:
first;second;third;something something something something;four
first;second;third;something
something
something something;four
I opened this in Notepad++ and i see that end of record has LF white tag and new lines in cell has CR white tag.
How can I remove this CR white tags? I would like to have after convert:
first;second;third;something something something something;four
first;second;third;something something something something;four
Answer 1: Provided you can uniquely identify where you want to remove the newline
Find: “(Pattern 1 at end of line)\r\n” - Replace with “\1”
Or Find: “(Pattern 1 at end of line)\r\n(Pattern 2 at start of next line)\” - Replace with “\1\2”
Answer 2: Instead if you can identify where you want to keep the newlines
Find: “(Pattern 1 at end of line)” – Replace with “\1QAZ” where “QAZ” is not anywhere in the file. Continue until "QAZ" is everywhere you require
Remove all new lines by Find “\r\n” – Replace with nothing.
Restore required new lines by Find “QAZ” – replace with “\n” – windows Notepad++ does not need the \r
Due to a new coding style that I've been having to use I'm required to use tabs in the beginning of lines but spaces everywhere else to align things.
Is there a way to customize notepad++ to only replace tabs with spaces if it's not at the beginning of a new line?
Just as an example of what I mean I'll use this bit of 'code':
function someFunction():
while(true):
veryLongCodeStuff() // Some comment
shortCode() // Aligned comment
Which I would have to write like this (where \t = tab and a "." represents a space):
function someFunction():
\twhile(true):
\t\tveryLongCodeStuff()..// Some comment
\t\tshortCode()..........// Aligned comment
To convert existing files, I would suggest a two step approach:
replace all tabs with spaces (this can be done with Edit -> Blank operations -> TAB to Space )
replace spaces at the beginning of lines: do a regular expression find/replace like this:
Open Replace Dialog
Find What: ^([\t]?)( ){4} instead of 4 use the number of spaces you have configured as tab width
Replace With: \1\t
check regular expression
click Replace All: as each Replace All replaces only one indent level for all lines: repeat until the status bar of the find dialog tells you, that no more replacements were done (just keep Alt-A pressed for a second or two)
I am trying to replace in Notepad++ using the Replace module, the below paragraph in html (i have 30 html file, and need to replace the below in all of them)
<script type="text/javascript">
<!--
var slideInterval=20000;
var slideTransition=3500;
var slideArray=["/background1.jpg","background2.jpg"];
jQuery.fx.interval=33;
// -->
</script>
But Notepad++ doesn't let me replace unless it's a line instead of a paragraph, and if i put everything on one line to replace, i will have another problems to worry about in my html.
I hope you have a work around on that.
I found a good way to use a multi-line "find" or "replace". I just copy pasted the paragraph into the Ctrl+H "find" field, then brought another paragraph and pasted it into the "replace" field. Notepad++ will show a tabbed space that means a line break. And voila, you can "Replace in all open documents" with just a single click.
N.B.: the "copy" operation should be within Notepad++, otherwise it would paste only the first line in either fields.
Update:
To be clearer about my answer, i found out that Notepad++ will let me only Paste once. That means, if i Copy a paragraph, i can paste it WITH its line break in the "find" field for example but if i paste it another time in the replace field, it will paste only the first line. Hence, no more than 1 "paste" operation is allowed into the Ctrl+H box in case i want to "paste" the line break.
So, in order for this to be done, first, i select any text i want and Ctrl+C on it, then, i go for the paragraph to be found, i just "Select" it and hit Ctrl+H: Notepad++ automatically shows the already selected text into the "find" field. Secondly, we "Paste" the text that's already in our clipboard into the "Replace" field. And the line breaks are here!
In brief: Select text --> Ctrl+C --> Select text --> Ctrl+H --> Ctrl+V in "replace field"
I think I found a guide that describes what you're looking for. The author has examples and the results, and some multi-line replacements are included. You should be able to extrapolate what he does over multiple files by clicking "Replace All in All Opened Documents".
http://markantoniou.blogspot.com/2008/06/notepad-how-to-use-regular-expressions.html
I am making a small online database that is accessible through the form of checkboxes for download. I was wondering if there was some way to list all of the filenames available for download in Sublime Text 2 and insert the same code around each filename?
Everything is functional, it would just save me a lot of repetitive copy and pasting if there is a faster way to do this.
Use SublimeText Find & Replace. Click the Regex button (it looks like a * to the left of the search box)
In the Find box, insert: (^.*$)
In the replace box: [yourcode]$1[yourcode]
Where [yourcode] is what you want to insert into the box.
So, if you want to make them all <li> then your replace box would be:
<li>$1</li>
Remember to use escape \ characters where they are needed, in case you need to insert restricted characters.
^ - beginning of a new line.
. - wildcard
* - any number of the previous character in the sequence (in this case a wildcard, so any text)
$ - the end of a line
() - denotes a block, it's how the $1 knows what text to put in it's place.
Sublime Text Search and Replace
Use search/replace on a text editor with regular expressions.
^ and $ represent the beginning and end of a line - thus allowing you to easily surround each line with the appropriate text.
Sometimes you can copy the newline character (as in copy the end of one line to the beginning of the next line), and replace that with whatever text you need.
You could always use the regular expression search / replace feature in Notepad++.
I am very new to Sublime Text and I am sure this is a naive question. Watching the Multiple line selection at http://www.sublimetext.com/ (2/6 slide). Absolutely love it.
I understand that Ctrl (Cmd)+Shift+L "multiple-selects" so that we could do the edit simultaneously. However, in the demo, they also merge all the lines into 1 single line. What is the shortcut for that?
I used Ctrl+J but it just deletes once and not all the occurrences of new line.
I use TextPad and use Find/Replace \n with an empty space. But it seems that the person giving the demo uses some kind of shortcut.
A single command shortcut for merging multiple lines into 1 is "join lines".
Command + Shift + J on the Mac to join lines.
CTRL + Shift + J on Windows
Edit > Lines > Join Lines
Important note: This keyboard shortcut changed in versions of sublime text released after around mid-2021. For older versions, use Command + J, or CTRL + J.
Another approach is seen in the demo animations on sublimetext.com. Using multiple selections, Ctrl+Shift+L is used to split a selection into lines, and each line is then edited simultaneously. end + del will then remove all line breaks. This can be seen in slide 2/6 at http://sublimetexttips.com/7-handy-text-manipulation-tricks-sublime-text-2/
I think that, in the demo, he presses Del, with the cursor at the end of the line, in multiple selection. This way the \n is removed in every selected line.
ctrl+a and ctrl+j seems working on sublime text 3.
Editing
join Joins the following line to the current line, replacing all in between whitespace with a single space
http://www.sublimetext.com/docs/commands
Go to edit option in menu, Edit -> line -> join lines
Select the lines you want to merge and press Ctrl + j and if you want to make all file in 1 line then do Ctrl + a and Ctrl + j.
If you want to merge lines into one line that will also remove the starting, and ending space from the line, the following regex should work:
Find What: ^\s*(.+)\s*\n
Replace With: \1
Sublime Text 3 for Mac:
cmd + j no longer works and is now CMD + SHIFT + J
Join lines is a good command, but it adds spaces between the merged lines. To merge lines without spacing, the easiest way appears to be the following:
Find -> Replace (Command+Option+F on Mac)
Ctrl+Enter to enter newline to the Find What field.
Don't enter anything into the Replace With field.
Press Replace All.
I have been using a regex approach in Sublime Text 3, as follows:
Press Ctrl+H (in Windows) to show the "Find and Replace" dialog at the bottom.
In the "Find" field, use $\n\s* (end of line, carriage return and any arbitrary number of spaces following, including zero, which should be at the beginning of the next line).
The "Replace" field should be empty.
Hit "Replace All" or Alt+Ctrl+Enter.
This should do the trick!