Regular expression find/replace notepad++ - regex

I've a huge text file with lines like this:
080012;Bovalino;RC;CAL;0964;89034;B098;9021;http://www.website-most.en/000/000/
And i would like extract only:
080012;***Bovalino***;***RC***;CAL;***0964***;***89034***;B098;9021;http://www.website-most.en/000/000/
And delete all other text.
Can this be done with regular expressions?

You can capture the stuff you want to keep and use a backreference in the replacement string:
Find what: ^\d*;(\w*;\w*);\w*;(\d*;\d*).*
Replace with: \1;\2
And make sure you do not tick the . matches newline option.
With Notepad++ 6 you can also use $1;$2 for the replacement (with the same meaning).
If the different fields may contain all sorts of characters and not just digits and letters, this is probably your best bet:
Find what: ^[^;]*;([^;]*;[^;]*);[^;]*;([^;]*;[^;]*).*

Related

Find and replace using regular expressions - remove double spaces between letters only

Trying to do this in the Atom editor (1.39.1 x64, uBuntu 18.04), though assume this applies to other text editors using regular expressions.
Say we have this text:
This text has some double-spaces. Lets try to remove them.
But not after a full-stop or if three or more spaces.
Which we would like to change to:
This text has some double-spaces. Lets try to remove them.
But not after a full-stop or if three or more spaces.
Using Find with Regex enabled (.*), all occurrences are correctly found using: [a-zA-Z] [a-zA-Z]. But what goes in the Replace row to enforce the logic:
1st letter, single space, 2nd letter?
You can use this
([a-z])\s{2}([a-z])
and replace by $1 $2
Regex Demo
If your editor supports lookarounds you can use
(?<=[a-z])\s{2}(?=[a-z])
Replace by single space character
Regex demo
Note:- don't forget to use i flag for case insensitivity or just change the character class to [a-zA-Z]

Notepad++ regular expressions and replace

I have a couple of sentences that need processing using regular expressions. They're in a text file and I'm opening it in notepad++.
<tag>There are two tags here</tag>
<tag>How am i supposed to
feel when this is happening?</tag>
<tag>I'm not sure.
But oh well<tag>
Is it possible to use notepad++'s regular expressions and replace functionality to produce an output like so:
<tag>There are two tags here</tag>
<tag>How am i supposed to feel when this is happening?</tag>
<tag>I'm not sure. But oh well<tag>
So that sentences that span over two or more lines are joined based on the fact that there is a > at the end of the sentence. Thanks.
Replace this:
[\r\n]+(?!<)
with a space
Click for Demo
Explanation:
[\r\n]+ - matches 1+ occurrences of a \r or \n
(?!<) - negative lookahead to validate that the above match is not followed by an opening tag <
Before Replacement with space:
After replacing the matches with space:

replace regular expression in sublime text

I have application where few labels are written like
ui-label-Display Not Masked
Now I want to replace it by
ui-label-Display_Not_Masked
so i have written search regex by
ui-label-(\w+ )*
This searches all expression but I am not able to create a expression to replace this text as required.
I have written one regex
$1_
which replaces
ui-label-Display Not Masked
by
ui-label-Display Not_Masked
This cannot be done with a single regex in a single iteration.
You have two choices:
Replace (ui-label-\w+) (note the space at the end) with $1_ until it no longer matches anything.
Make a looong regex with as many capture groups as necessary, i.e. (ui-label-\w+) (?:(\w+)(?: (\w+))?)? and replace with $1_$2_$3.

Replace leading spaces with Notepad++

I'd like to use Notepad++ to replace all leading spaces on a line with a like number of given characters. So for instance, I want to change:
zero
one
two
three
into:
zero
#one
##two
###three
I haven't been successful at getting this working. I did find Regex to replace html whitespace and leading whitespace in notepad++, but wasn't able to get the result I wanted.
Is this possible with Notepad++? I'd rather not have to write code to do this...
As Tim's answer indicates, this can't be done in a single search/replace, however here is how you can accomplish the same task fairly quickly using multiple replacements:
Find: ^( *)[ ]
Replace with: \1#
Now just spam the "Replace All" button until it indicates that there were no matches to replace. This will replace a single space at the beginning of each line on each click, so it will require the same number of clicks as your most-indented line.
Make sure "Regular expression" is selected as the search mode.
You would need variable-length lookbehind assertions to do this in a single regex, and Notepad++ doesn't support these.
For the record, in EditPadPro you can search for (?<=^ *)\s and replace with #.

notepad++ regex remove numbers

I have a notepad++ text file with:
have 9456
do 9823781
no 83270
tell 342
and it continues like that.
What is the regex for removing the space and numbers from the file?
You want to replace [0-9 ]+ with empty string with the regex option enabled.
Use the following as your search string:
\d+$
Remember to have the Search Mode set to Regular Expression.
Find space and digits easy as one two three
Search \s\d+
Replace all with: nothing