Notepad++ Search and Replace: delete all after "/" in each row - regex

I have a plain text file with content like this:
prežrať/RN
prežrieť/Z
prežrúc/zZ
prežuť/c
...
Q: How can I remove all strings after / symbol in every row in Notepad++?
Desired output:
prežrať
prežrieť
prežrúc
prežuť
...
I am doing this with Find-and-Replace for every different string after /, but there are too many combinations.

Search for: /.*, replace with nothing.
The character / matches just /. ., however, matches any character except newlines, so .* will match a sequence of characters up until the first newline. You can find a demonstration here: http://regex101.com/r/kT0uE3.
If you want to remove characters only after the last on the line /, you should use the regex /[^/]*$. You can find an explanation and demonstration here: https://regex101.com/r/sZ6kP7/74.

In regular expression mode
Find:
/.*
Replace:
(empty)

Set find and replace to regular expression mode.
Find string: /.*
Replace String: (empty string)
Notepad++ find and replace is by default line ended (it won't go over multiple lines)

Using find and replace:
Hit CTRL-H to open the Replace dialogue box
enter /.* into "Find what"
leave "Replace with" empty
Select "Regular expression" (and .matches newline if it is single line)
Click on Replace
Here we go... You are done.

Related

Regex to match the last character if it is a dot

In OpenOffice Calc how do I remove the last character if it is a dot?
Example:
dog
cat.
rabbit
It becomes:
dog
cat
rabbit
What regex would you use to obtain that?
Regular expression:
To match a ., you have to write \., because . has a special meaning in regular expressions.
To match the end of the line, you have to write $.
Putting it all together, I would use this regular expression: \.$. This will match a dot if it's at the end of the line. Demo
Removing the matched dots:
Open "Find & Replace" window by pressing Ctrl+H
Type regular expression from above into "Search for" field, this is what you want to be replaced
Leave "Replace with" field empty, as you want to replace with nothing, which means it will remove the matched content (the dots)
Under "More/Other options", turn on "Regular expressions"*
Click on "Replace" or "Replace all" button to perform the replacements
Please see documentation of this Calc feature for further details.
In OpenOffice Calc how do I remove the last character if it is a dot?
=IF(RIGHT(A1)=".";LEFT(A1;LEN(A1)-1);A1)

Notepad++ Regex Mark

I have a list like this
randomtext.html
file1
file1
file2
I want to mark the first line after the line ended with html. So, it should marked the first "file1" only
Have a try with:
Within Mark tab
Find what: html\R\K.+
Be sure you haven't chck . matches newline and check Mark lines then click on Find All
Explanation:
html : Literally html
\R : any kind of line break (ie. \n or \r or \r\n)
\K : forget everything found before
.+ : Everything until the next line break. (ie. the second line).
First of all i would like to ask what do you mean by mark?
Press ctrl+h. Select regular expression and you can use following regular expression:-
Find: (.* )html\r\n(.)\r\n(.)
Replace: $1html\r\n-------$2\r\n$3
Here i have use '-------' as the mark, you can put the mark according to your need.

Notepad++ regex -> newLine

I use Notepad++ and I need to delete all lines starting with, say "abc".
Attention, I don't need to replace the line starting with "abc" with a empty line, but I need to completely delete these lines.
How do I proceed (using regex, I suppose)?
Try replace
^abc.*(\r?\n)?
with
nothing
The ^ indicates the start of a line.
The . means wild-card.
The .* means zero or more wild-cards.
x? means x is optional.
The \r?\n covers both \r\n (generally Windows) and \n (generally Unix), but must be optional to cover the last line.
Search for this regular expression
^abc.*\r\n
Replace with nothing.
Searching a little bit more on regex in Notepad++ I discovered that the new line character is not \n as I expected (Windows), but the \n\r.
So, my regex replace expression should be:
Find: abc.*\r\n
Replace with: (nothing, empty field)
Try the regex \nabc.* in "Find and Replace" --> "Replace"
Leave "Replace With" field empty.
EDIT : This won't work with first like (because '\n' means "new line")
Press Ctrl+H to bring up the Replace window. Put
^abc.*(\r?\n)?
in the Find what and leave Replace with empty. Select Reqular expression and hit Replace All.
This reqular expression handles all the edge cases:
When the first line of the file starts with abc
When the last line of the file starts with abc and there is no new line at the end of the file.

Notepad++ RegEx Search/Replace: How to append and prepend a character at start and end of each file line?

How to append and prepend a character at start and end of each file line?
I have this file structure:
140","Bosnia
160","Croatia
170","Serbia
180","Montenegro
200","Slovenia
What I need is to add a double quote " at the start and at the end of each file line, using regular expressions in Notepad++ editor.
Thanks!
Just search for
(.*)
and replace with
"\1"
with regular expression option activated. Regular expressions are working only on a row bases, so (.*) matches the complete row and because of the brackets around you can access the match using \1.
Try searching ^(.*)$ and replacing by "$1".
bye ;)
You can match the whole, even an empty line, with
^.*$
You can match a non-empty line with
^.+$
You may match a non-blank line with
^\h*\S.*$
Now, all you need to do to wrap these lines with any text of your choice, you need to use the backreference to the whole match (see Replace with whole match value using Notepad++ regex search and replace):
"$0"
"$&"
"$MATCH"
"${^MATCH}"
If you need to wrap the whole line with parentheses, you will need to escape them since ( and ) are "special" in the Notepad++ replacement pattern, \($&\).
Whenever you need to insert a backslash, make sure you double it, \\$&\\.

Remove Numbers in Notepad++

I have here a text file
with
245. asdasd
45. asdasd
42. gfhfgh
5353. sdfsdf
want to remove all numbers in front of it.
try it already with find and replace [0-9].
Ctrl+F - Replace - Search mode: regular expression
Find What: [0-9]+
Replace With:
// Replace with is empty
Ctrl-H - shows replace.
Ensure that 'regular expression' is on.
Use ^[0-9]+
Note begging ^ used to mark begin of line. Remove it if need remove all numbers
use RegEx search (should be ^\d+ for numbers with more than 1 digit):
On the replace tab switch to regular expressions; Search for ^\d+\.\s and leave Replace With empty.
(Matches start of line, any number, a dot, trailing space)
You should try to use this regular expression to remove what you want in the replace dialog:
^[0-9]*\.\ (.*)
And replace with:
\1
To search for digits:
Find what: [[:d:]]
Select: o Regular Expression
To remove only "line numbers with dots" use
[0-9]+.
To remove digits only from start of string
Input : 123. asdasd 3434
Output: . asdasd 3434
Replace All using below regex with o or more spaces in start of string
^\s*\d+
For Numbers
Ctrl H
Find what: [0-9]
Replace With:
(leave replace with blank)
For Period
Ctrl H
Find what: .
Replace With:
(leave replace with blank)