Hello I have this kind of data :
a;b;c;d
1;2;3;4
a;g;h;j
f;g;f;d
a;d;8;d
And I would like to modify to have this :
a;bc;d
1;23;4
a;gh;j
f;gf;d
a;d8;d
Obviously I have a lot of lines but every time the semi colons are in the same position. I tried to select the columns with notepad++ and to to replace the semi colon by nothing but the box is grey...
Do you have a solution ?
Thank you !
Here is an online regex tester that i did the work on, you can just replace your data with the samples.
Regex : (\w+;)((\w+);(\w+))(;\w+)
DEMO
Hold ALT+SHIFT and use the arrow keys to select second semicolon and delete it.
OR
Hold ALT and click and drag the mouse to select a second semicolon and delete it.
OR
Find : ^(...)(.)
Replace with: \1
Ctrl+H
Find what: ^[^;]+;[^;]+\K;
Replace with: LEAVE EMPTY
check Wrap around
check Regular expression
Replace all
Explanation:
^ # beginning of string
[^;]+ # 1 or more non semicolon
; # 1 semi colon
[^;]+ # 1 or more non semicolon
\K # forget all we have seen until this position
; # 1 semi colon
Result for given example:
a;bc;d
1;23;4
a;gh;j
f;gf;d
a;d8;d
If the possible values of the data are lowercase characters a-z or a digit you could also capture the first 3 characters using a capturing group and a character class [a-z0-9] and after that match a semicolon. If there can be more than 1 character you could use a quantifier + for the character class like [a-z0-9]+
Then replace with the first capturing group.
Find what
^([a-z0-9];[a-z0-9]);
Replace with
$1
Regex demo
Or Using \K you could find ^[a-z0-9];[a-z0-9]\K; and leave Replace with empty.
Related
I am currently trying to convert a list of 1000 words into this format:
'known', 'buss', 'hello',
and so on.
The list i have is currently in this format:
known
worry
claim
tenuous
porter
I am trying to use notepad++ to do this, if anybody could point me in the correct direction, that would be great!
Use this if you want a comma delimited list but no extra comma at the end.
Ctrl+H
Find what: (\S+)(\s+)?
Replace with: '$1'(?2,:)
CHECK Wrap around
CHECK Regular expression
Replace all
Explanation:
(\S+) # group 1, 1 or more non spaces
(\s+)? # group 2, 1 or more spaces, optional
Replacement:
'$1' # content of group 1 enclosed in quotes
(?2,:) # if group 2 exists, add a comma, else, do nothing
Screen capture (before):
Screen capture (after):
How about replacing (\S+) with '$1'? Make sure your Regular Expression button is selected in the Find and Replace tool inside Notepad++
Explanation
(\S+) is regex for repeating non-whitespace characters (1 or more). Wrapping it in parenthesis puts it in a capture group which can be accessed in numerical order by using a dollar sign ($1).
'$1' will take that found text from the Find above and replace it with capture group #1 ($1) wrapped in single quotes '.
Sample
Input: known worry claim tenuous porter
Output: 'known' 'worry' 'claim' 'tenuous' 'porter'
How would you use the regex in Notepad++ to format replacing a single character that it finds in every line excepts for the duplicate ones in the certain line further?
test1:_|TEST:-TEST.|
test2:_|TEST:-TEST.|
test3:_|TEST:-TEST.|
As shown in the test code, there are two colons; I'm trying to replace the first colon with each line to a ; and NOT the second one found; the result of me doing the regex should equal to this:
test1;_|TEST:-TEST.|
test2;_|TEST:-TEST.|
test3;_|TEST:-TEST.|
Ctrl+H
Find what: ^.+?\K:
Replace with: ;
CHECK Wrap around
CHECK Regular expression
UNCHECK . matches newline
Replace all
Explanation:
^ # beginning of line
.+? # 1 or more any character but newline, not greedy
\K # forget all we have seen until this position
: # colon
Screen capture (before):
Screen capture (after):
I'm guessing that maybe this expression,
(\w+)\s*(?::)(\s*_\s*\|\s*\w+\s*:\s*-\w+\.\|)
with a replacement of $1;$2 might work.
DEMO 1
Or with less boundaries, this expression:
([^:]+):(.*)
with the same replace.
DEMO 2
It's done like this
Find (?m)^[^:\r\n]*\K:
Replace ;
https://regex101.com/r/rT1vG9/1
I want to replace character - using regular expression in my text so it would work like this:
Original text: abcd-efg-hijk-lmno
Text after replacing: abcd-efg-hijk/lmno
As you can see I want to replace character - starting from the end just one time with character /.
Thanks in advance for any tips
Find what: -([^-]*)$
Replace with: /$1
Search Mode: Regular Expression
Explanation:
- : a dash
([^-]*$) : text with no dash,
zero or more times,
to the end of the line,
put in the $1 variable
/$1 : literal "/", contents of $1
Good resource: http://www.grymoire.com/Unix/Regular.html
To replace characters in Notepad++, you can open the Replace window using Ctrl+H, or under the "Search" menu. Once open, enter the following regular expression:
(.{4}-.{3}-.{4})(-)(.{4})
This will find:
a group of four characters (the "." being any character, the "{4}" being the quantity),
a dash,
a group of three characters,
another dash,
a group of four characters,
again another dash,
then a group of four characters.
The parentheses group this search into captured groups, which we will use for the replacement part. See https://www.regular-expressions.info/brackets.html for more info.
If you want to restrict the search to lowercase letters as in your example, you would replace the "." with "[a-z]", or for upper and lower "[a-z,A-Z]".
Now for the replacement. The groups from earlier are referenced by the dollar sign then the number, e.g. $1 would be the first. So we will replace the characters found with the first group ($1), disregard the second group containing the dash and insert the "/" instead, then include the third group ($3):
$1/$3
The settings in the replace window need to have "Regular expression" and "Wrap around" checked, and ". matches newline" unchecked.
You can then click Replace all to replace all occurrences, or go through using Replace individually.
Since the beginning and end of line characters are not included, you can find multiple occurrences of this pattern on a single line.
Note: This answer follows the same procedure as Toto's, however uses a different regular expression.
Ctrl+H
Find what: ^(.+)-([^-]+)$
Replace with: $1/$2
check Wrap around
check Regular expression
DO NOT CHECK . matches newline
Replace all
Explanation:
^ : begining of line
(.+) : 1 or more any character, catch in group 1
- : a dash
([^-]+) : 1 or more any character but dash, catch in group 2
$ : end of line
I'm trying to generate a regex to catch anything (include newlines) after AS until SELECT to remove the AS.
There are multiple variations, and I want to repeat everytime there is an INSERT. Some don't have AS at all and should do nothing.
INSERT OVERWRITE schema.table1
AS
SELECT
INSERT OVERWRITE schema.table2
AS -- (some spaces sometimes here)
SELECT
I only want to remove Lines that start with AS, otherwise some other words might get changed.I can't figure out how to do a lazy regex that only does this, any help would really be appreciated.
Reged that you want: AS[\d\D]*?(?=SELECT)
You can look the demo here.
https://regex101.com/r/IFNqbG/3
Ctrl+H
Find what: (INSERT\b.*?\R)AS.*?\R(?=SELECT\b)
Replace with: $1
Replace all
Explanation:
( : start group 1
\bINSERT\b : literally 'INSERT', with word boundaries to not match 'INSERTED' for instance
.*? : 0 or more anycharacter, not greedy
\R : any kind of linebreak
) : end group 1
AS\b : literally 'AS', with word boundary to not match 'ASSIGN' for instance
.*? : 0 or more anycharacter, not greedy
\R : any kind of linebreak
(?=SELECT\b) : lookahead, make sure we have SELECT after but not SELECTED
CHECK . matches newline if INSERT or AS lines can be on multiple lines
Replacement:
$1 : group 1
Result for given example:
INSERT OVERWRITE schema.table1
SELECT
INSERT OVERWRITE schema.table2
SELECT
In Notepad++, I'd like to replace only the first and second comma (","), by ":".
Example :
blue,black,red -> blue:black:red (2 first commas replaced)
blue,black,red,yellow -> blue:black:red,yellow (third comma still here)
Thanks!
I believe you can do this by replacing this regex:
^([^,]*),([^,]*),(.*)$
With this:
$1:$2:$3
For compatibility with cases where there are less than 2 commas, use these:
^(([^,]*),)?(([^,]*),)?(.*)$
$2:$4:$5
Something along this line,
^([^,]*),([^,]*),(.*)$
And replace with
$1:$2:$3
Or \1:\2:\3
Just two capturing groups is enough.
Regex:
^([^,]*),([^,]*),
Replacement string:
$1:$2:
DEMO
Explanation:
^ Asserts that we are at the start.
([^,]*) Captures any character not of , zero or more times and stored it into a group.(ie, group 1)
, Matches a literal , symbol.
([^,]*) Captures any character not of , zero or more times and stored it into a group.(ie, group 2)
, Matches a literal , symbol.
Well you can try to capture the parts in groups and then replace them as follows:
/^([^,]*),([^,]*),(.*)$/$1:$2:$3
How does it work: each line is matched such that the first part contains all data before the first comma, the second part in between the two commas and the third part all other characters (including commas).
This is simply replaced by joining the groups with colons.
A no-brainer; virtually "GREP 1-0-1". Not really an effort.
Just find
^([^,]+),([^,]+),
and replace with
\1:\2:
Click on the menu item: Search > Replace
In the dialog box that appears, set the following values...
Find what: ^([^,]+),([^,]+),
Replace with: $1:$2:
Search Mode: Regular expression