Notepad++ Regex Ending With - regex

I want to remove all the lines until some terminating string. So something like this :
These
lines
|| that can contain numbers 123 or characters like |*{
will be removed
But the following lines
will
remain.
I want to obtain :
But the following lines
will
remain.
I tried searching the regexp /removed$/ and replacing with an empty string, but it says 0 matches.
How can I do this?
Thanks for any help !

Make sure you check ". matches newline", and use .*removed\.$:
Notice that you need .* at the start to match everything up until the terminating string, and you have to escape the literal . at the end.
Also, Notepad++ doesn't want slashes around its regexes.
If you don't have the . at the end of your terminator, just remove the \. from the regex.
To remove the trailing newline as well, you could use .*removed\r?\n?.

Related

regex to remove everything after the last comma in a string

I would like to write a regex in Perl which will remove everything after the last comma in a string. I know the substring after the last comma is a number or some other substring, so no commas there.
Example: some\string,/doesnt-really.metter,5.
I would like the regex to remove the last comma and the 5 so the output would be: some\string,/doesnt-really.metter
I am not allowed to use any additional module only with regex. So which regex should I use?
Another example:
string_with,,,,,_no_point,some_string => string_with,,,,,_no_point
If the comma is always followed by one or more digits, you can use: s/,\d+$//. More generally, use s/,[^,]*$// (match a comma followed by zero or more non-comma characters followed by end-of-string).
This Regex captures everything before the last ,.
(.*),[^,]*$
perl -n -e 'chomp; s/(.+,)/$1/g; print "$_\n";' inputfile.txt
Just run this command directly on terminal, the regex just selects all text which comes before last comma).

Regex find STRING, but ignore lines, that have //.* before STRING [duplicate]

I try to verify a CSV file where we had problems with line breaks.
I want to find all lines not starting with a ".
I am trying with /!^"/gim but the ! negation is not working.
How can I negate /^"/gim properly?
In regex, the ! does not mean negation; instead, you want to negate a character set with [^"]. The brackets, [], denote a character set and if it starts with a ^ that means "not this character set".
So, if you wanted to match things that are not double-quotes, you would use [^"]; if you don't want to match any quotes, you could use [^"'], etc.
With Notepad++, you should be able to search with the following to find lines that don't start with the " character:
^[^"]
If you want to highlight the full line, use:
^[^"].*
In Notepad++ you can use the very usefull negative lookahead
In your case you can try the following:
^(?!")
If you want to match wholes lines add .+ or .{1,7} or anything e.g.:
^(?!").*
will also match empty lines.
Explanation part
^ line start
(?!regexp) negative lookahead part: this means that if the regexp match, the result will not be shown
Step 1 - Match lines. Find dialog > Mark tab, you can bookmark lines that match.
Step 2 - Remove lines bookmarked OR Remove lines not bookmarked. Search > Bookmark > Remove Unmarked Lines or Remove Bookmarked lines

Find lines not starting with " in Notepad++

I try to verify a CSV file where we had problems with line breaks.
I want to find all lines not starting with a ".
I am trying with /!^"/gim but the ! negation is not working.
How can I negate /^"/gim properly?
In regex, the ! does not mean negation; instead, you want to negate a character set with [^"]. The brackets, [], denote a character set and if it starts with a ^ that means "not this character set".
So, if you wanted to match things that are not double-quotes, you would use [^"]; if you don't want to match any quotes, you could use [^"'], etc.
With Notepad++, you should be able to search with the following to find lines that don't start with the " character:
^[^"]
If you want to highlight the full line, use:
^[^"].*
In Notepad++ you can use the very usefull negative lookahead
In your case you can try the following:
^(?!")
If you want to match wholes lines add .+ or .{1,7} or anything e.g.:
^(?!").*
will also match empty lines.
Explanation part
^ line start
(?!regexp) negative lookahead part: this means that if the regexp match, the result will not be shown
Step 1 - Match lines. Find dialog > Mark tab, you can bookmark lines that match.
Step 2 - Remove lines bookmarked OR Remove lines not bookmarked. Search > Bookmark > Remove Unmarked Lines or Remove Bookmarked lines

How to terminate a regular expression and start another

I have a file which have the data something like this
34sdf, 434ssdf, 43fef,
34sdf, 434ssdf, 43fef, sdfsfs,
I have to identify the sdfsfs, and replace it and/or print the line.
The exact condition is the tokens are comma separated. target expression starts with a non numeric character, and till a comma is met.
Now i start with [^0-9] for starting with a non numeric character, but the next character is really unknown to me, it can be a number, a special char, an alphabet or even a space. So I wanted a (anything)*. But the previous [] comes into play and spoils it. [^0-9]* or [^0-9].*, or [^0-9]\+.*, or [^0-9]{1}*, or [^0-9][^,]* or [^0-9]{1}[^\,]*, nothing worked till now. So my question is how to write a regex for this (starting character a non numeric, then any character except a comma or any number of character till comma) I am using grep and sed (gnu). Another question is for posix or non-posix, any difference comes there?
Something like that maybe?
(?:(?:^(\D.*?))|(?:,\s(\D.*?))),
This captures the string that starts with a non-numeric character. Tested here.
I'm not sure if sed supports \D, but you can easily replace it with [^0-9] if not, which you already know.
EDIT: Can be trimmed to:
(?:\s|^)(\D.*?),
With sed, and slight modifications to your last regex:
sed -n 's/.*,[ ]*\([^ 0-9][^\,]*\),/\1/p' input
I think pattern (\s|^)(\D[^,]+), will catch it.
It matches white-space or start of string and group of a non-digit followed by anything but comma, which is followed by comma.
You can use [^0-9] if \D is not supported.
This might work for you (GNU sed):
sed '/\b[^0-9,][^,]*/!d' file # only print lines that match
or:
sed -n 's/\b[^0-9,][^,]*/XXX/gp' file # substitute `XXX` for match

VIM: cycle through string

I'm trying to change in an url all text longer then 6 characters to 6characters~1 p.e.
c:\program files\vim directory\vim73\ to
c:\progra~1\vimdir~1\vim73
I have found a way to find the string length between "\ \"
strlen(matchstr("c:\program files\vim directory\vim73\","\\\zs.*\ze\\"))
but how can I cycle through a string?
How can I cut it to 6 characters (removing the spaces if there are) and put "~1" behind it?
This seems to work for your example text but I'm not sure it would work in all cases (assumes your filename is on it's own line, you could modify it to be more specific otherwise):
:s# ##ge|s#\v\\\zs(\w{6}).{-}\ze\\#\1\~1#&
Edit: just noticed that this leaves a trailing slash. If you want that removed too you can use the following instead:
:s# ##ge|s#\v\\\zs(\w{6}).{-}\ze\\#\1\~1#&|s#\\$##&
I think this regex should do the trick:
:%s /\\\([^\\]\{6\}\)[^\\]*/\\\1\~1\\/g
It essentially means: Match the first 6 characters between two occurences of \ or one ocurrence of \ and newline. Remember those characters (\( ... \) is used to remember) and match everything else until the separator (newline or \). Substitute that with the first 6 characters and ~1.