Notepad++ remove text between string+bracket and another bracket - text

So, I've seen that you can remove between two characters and remove between two strings but I haven't been able to find a system that works between a string and a character.
I need to remove the numbers between the two brackets in...
provinces= {
923 6862 9794 9904 11751 11846 11882
}
Keep in mind that these files also contains other brackets which are needed. I've looked around for a solution for this but none seem to work :/
Thanks for the help.

This one will do the job:
Ctrl+H
Find what: \b(provinces\s*=\s*\{)[^}]+(\})
Replace with: $1$2
Replace all
Explanation:
\b : a word boundary
( : start group 1
provinces : literally "provinces"
\s* : 0 or more spaces
= : equal sign
\s* : 0 or more spaces
\{ : an open curly bracket, must be escaped because it has special meaning in regex
) : end group 1
[^}]+ : any character that is not a close curly bracket
(\}) : group 2, a close curly bracket, escaped.
Replacement:
$1$2 : group 1 then group 2

Related

how to match only once occurrence of a double space of a line?

line A
foo bar bar foo bar foo
line B
foo bar bar foo
In line A, there are multiple occurrence of double space.
I only want to match lines like line B which has only once double space occurrence.
I tried
^.*\s{2}.*$
but it will match both.
How may I have the desired output? Thank you.
If you wish to match strings that contain no more than one string of two or more spaces between words you could use following regular expression.
r'^(?!(?:.*(?<! ) {2,}(?! )){2})'
Start your engine!
Note that this expression matches
abc de fgh
where there are four spaces between 'c' and 'd'.
Python's regex engine performs the following operations.
^
(?! : begin negative lookahead
(?: : begin non-capture group
.* : match 0+ characters other than line terminators
(?<! : begin negative lookbehind
[ ]{2,} : match 2+ spaces
(?! ) : negative lookahead asserts match is not followed by a space
) : end negative lookbehind
) : end non-capture group
{2} : execute non-capture group twice
) : end negative lookahead
You can do:
^(?!.*[ \t]{2,}.*[ \t]{2,})
# Negative look ahead assertion that states 'only start the match
# on this line IF there are NOT 2 (or potentially more) breaks with
# two (or potentially more) of tabs or spaces'.
Demo 1
If you want to require ONE double space in the line but not more:
^(?=.*[ \t]{2,})(?!.*[ \t]{2,}.*[ \t]{2,})
# Positive look ahead that states 'only start this match if there is
# at least one break with two tabs or spaces'
# BUT
# Negative look ahead assertion that states 'only start the match
# on this line IF there are NOT 2 (or potentially more) breaks with
# two (or potentially more) of tabs or spaces'.
Demo 2
If you want to limit to only two spaces (not tabs and not more than 2 spaces):
^(?=.*[ ]{2})(?!.*[ ]{2}.*[ ]{2})
# Same as above but remove the tabs as part of the assertion
Demo 3
Note: In your regex you have \s as the class for a space. That also matches [\r\n\t\f\v ] so both horizontal and vertical space characters.
Note 2:
You can do this without a regex as well (assuming you only want lines that have 1 and only 1 double space in them):
txt='''\
line A
foo bar bar foo bar foo
line B
foo bar bar foo'''
>>> [line for line in txt.splitlines() if len(line.split(' '))==2]
['foo bar bar foo']
You can get the match without lookarounds by starting the match with 1+ non whitespace chars.
Then optionally repeat a single whitespace char followed by non whitespace chars before and after matching a double whitespace char.
The negated character class [^\S\r\n] will match any whitespace chars except a newline or carriage return. If you want to allow matching newlines as well, you could use \s
^\S+(?:[^\S\r\n]\S+)*[^\S\r\n]{2}(?:\S+[^\S\r\n])*\S+$
Explanation
^ Start of string
\S+ Match 1+ non whitespace chars
(?: Non capture group
[^\S\r\n]\S+ Match a whitespace char without a newline
)* Close group and repeat 0+ times
[^\S\r\n]{2} Match the 2 whitespace chars without a newline
(?: Non capture group
\S+[^\S\r\n] Match 1+ non whitespace chars followed by a whitespace char without a newline
)* Close group a and repeat 1+ times
\S+ Match 1+ non whitespace chars
$ End of string
Regex demo

How to parse a list of text separated by multi-character delimeters

To parse a comma separated list of text (no comma escapes allowed) I can use this,
main: Text (Sep Text)*;
Sep: ',';
Text: ~','*;
Now I'd like to modify the parser to use two commas instead of one as a separator.
Clearly this doesn't work,
main: Text (Sep Text)*;
Sep: ',,';
Text: ~',,'*;
How can I accomplish this? Is it possible for the lexer to return a single token with the text? And is it possible without actions\predicates?
No, you can't negate 2 (or more) characters (~',,' is invalid).
You could do this:
main : Text (sep Text)* EOF;
sep : Comma Comma;
Comma : ',';
Text : ~',' ( ~',' | ',' ~',' )*;
Where Text matches a non-comma (~','), followed by zero or more:
non-commas (~','), or
a single comma, followed by a non-comma (',' ~',')

Remove both duplicates (original and duplicate) from text notepad++

I need to remove both duplicates like:
admin
user
admin
result:
user
I have tried but none works for notepad++
You have to sort your file before apply this (for example using the plugin TexFX).
Ctrl+H
Find what: ^(.+)(?:\R\1)+
Replace with: NOTHING
check Wrap around
check Regular expression
DO NOT CHECK . matches newline
Replace all
Explanation:
^ : Beginning of line
(.+) : group 1, 1 or more any character but newline
(?: : start non capture group
\R : any kind of linebreak
\1 : content of group 1
)+ : end group, must appear 1 or more times

How do i Remove text in between and around other text in notepad++

I need to clear text around other text... example:text = hello there sir how are you doing
Tex to be removed = hello sir are doing
Result = there how you
What would i put in to skip all other text but the words in the text to be removed with the ctrl h menu.
You may use a regex based search and replace:
Find what: \S+(?:\s+(\S+))?
Replace with: $1
See the regex demo
Details:
\S+ - one or more chars other than whitespace
(?:\s+(\S+))? - one or zero occurrences of
\s+ - 1+ whitespaces
(\S+) - Group 1: one or more chars other than whitespace
You can do find/replace with regexes in Notepad++.

vim: can not match whitespaces after tabs

I have text like this (1 or 0 tab + multiple whitespaces at line beginning):
(tab) There are a tab and 4 whitespaces before me. // line 1
(tab) There are a tab and 6 whitespaces before me. // line 2
There are 6 whitespaces before me. // line 3
There are 4 whitespaces before me. // line 4
When i use ^[\t\s]\s*, only line 1,2 are matched, line 3, 4 are not matched, why?
(When i use ^\s*, line 3 and 4 can be matched.)
Thanks!
It turns out that you can not use \s to match whitespace within [].
Just use to match it within [].
That is interesting. I'm not sure why the \s doesn't work inside of [] brackets. Perhaps it is because [] defines explicit characters and \s is ambiguous (it can stand for multiple characters). In other words \s stands for any whitespace, including a tab(\t). However, if you explicitly specify a space in this case (^[\t ]\s*) it will work.
As noted \s doesn't work within [], alternatively you could use the [:blank:] character class:
^[[:blank:]]\+

Resources