Working with EditPlus Text Editor-Regular Expression How To
Editplus is a lot better than the regular text editor, Notepad.
From all it’s features I like RegExp Support the most, and than comes the block select feature.
Here are the quick lines to carry out regular tasks using regular expression in Editplus. It’s kinda downloadable cheetsheet list.
Remove all empty lines:
Find: “^\n” (Ignore double-quotes in all find/replace)
Replace: “”
Where,
^ – Beginning of the line
\n – New Line
Remove Multiple Spaces convert into single space:
Find: ” +”
Replace: ” “
Where,
+ – find one or more occurance of space character.
Comment multiple line of code:
Find: “^”
Replace: “#” or “//”
You may optionally use: Edit Menu > Format > Line Comment.
Generate Comma Separated List from new line delimited list:
Find: “\n”
Replace: “, “
This helps in even joining some of lines of code instead of replacing by comma you may replace it with “”.
Manipulate columns display order / punctuation:
Find: “([0-9]+)\t([a-zA-Z]+)”
Replace: “\2\t\1”
Where,
[0-9]+ – Finds one or more digits
[a-zA-Z]+ – Finds one or more characters
() – mark the block or capture the group
\2 – 2nd mark expression
Eg:
123 abc
345 cde
567 efg
Becomes:
abc 123
cde 345
efg 567
The Other Way:
– Press Alt+C
– Drag you mouse to select respective column and click
– Copy / Cut as required
[ad#ad-2-300×250]
Append / Add semicolon (any character) at the end of the line:
Find: “\n”
Replace: “;\n”
Enclose lines by quotes:
Find: “\n”
Replace: “‘\n'”
Delete all lines containing a given STRING:
Find: “^.*STRING.*$”
Replace: “”
Remove lines not containing a given STRING:
I don’t know how to do this!! π
Convert tab separated file into insert statements:
TSV: abcd de4 iirn 34399
SQL: INSERT INTO TABLENAME VALUES (“abcd”, “de4”, “iirn”,”34399″);
Find: “(.*)\t(.*)\t(.*)\t(.*)”
Replace: “INSERT INTO TABLENAME VALUES (“\1”, “\2”, “\3″,”\4″);”
Format the telephone number:
Find: “([0-9][0-9][0-9])([0-9][0-9][0-9])([0-9].*)”
Replace: “\1-\2-\3”
Eg.:
Original: 1231231231
Formatted-1: 123-123-1231
Remove Brackets:
Find: “\(|\)”
Replace: “”
Where,
\( – Match (. \ is required to escape marking the expression.
| – or
Replace 1stΒ occurrenceΒ of character:
Find: ” (.*)”
Replace: “-\1”
Where,
(.*) – matches everything and marks the block
** Make sure you ignore double-quotes(“) while writing in find / replace boxes.
EditPlus supports following regular expressions in Find, Replace and Find in Files command.
Expression – Description
- \t – Tab character.
- \n – New line.
- . – Matches any character.
- | – Either expression on its left and right side matches the target string.
- [] – Any of the enclosed characters may match the target character.
- [^] – None of the enclosed characters may match the target character.
- * – Character to the left of asterisk in the expression should match 0 or more times.
- + – Character to the left of plus sign in the expression should match 1 or more times.
- ? – Character to the left of question mark in the expression should match 0 or 1 time.
- ^ – Expression to the right of ^ matches only when it is at the beginning of line.
- $ – Expression to the left of $ matches only when it is at the end of line.
- () – Affects evaluation order of expression and also used for tagged expression.
- \ – Escape character. If you want to use character “\” itself, you should use “\\”.
Notable Features of Editplus are :
- Spell checking
- Regex-based find & replace
- Encoding conversion
- Newline conversion
- Syntax highlighting
- Multiple undo/redo
- Rectangular block selection
- Auto indentation
- Code folding (Text folding)
Download pdf: Editplus-RegExp.
Thank on your wondeful guide.
can you please explain why you the *Caret* ^ here?
Delete all lines containing a given STRING:
Find: β^.*STRING.*$β
Replace: ββ
Thanks again
Bar
Hi Bar,
^ here represents Beginning of a line while $ represents end of the line.
So from the beginning (^) to end ($) delete lines whichever contains STRING.
eg.
this is the line
this is the line too
From above two lines if I replace using:
^this is the line$
only first line will get replaced but second.
I hope I’m making sense.
Thanks on your help
If you find how to delete only lines or exprssion that not contain a given String I happy to know
Or, if you know any other Program that allow that.
Thanks
Yoni
Can you tell how to truncate a line from a given char or string . what i wanted is as follows .
IND vs PAK – Delhi
AUS vs ENG – Dhaka
i want these to become
IND vs PAK
AUS vs ENG
ie trucate the line from the char “-” .
Arif,
search: (.*)-.*
replace: \1
Cheers.
I had a very big file and i used the search to find what i want and i did set marker for those line. How can i remove other lines which are not set to marked and copy only the lines which are set to marked.
Sruhi,
Sorry for the too much delayed response!
Well as written in the post “Remove lines not containing a given STRING:” is something I don’t know yet; It’s possible through some Linux Commands but editplus.. sorry π
Well I hope you must have overcome this issue by hook/crook though!
Thanks for visiting,
Kedar.
hello I need to replace
(1 nickname2
(2 nickname33
(3 nickname234
(4 nickname21
..(365355 nickname54
to
nickname2
nickname33
nickname234
nickname21
nickname54
what is the expresion to use ?
thank you
Hey,
Search: “\([0-9]+ ”
Replace: “”
(without quotes)
Enjoy π
Delete all lines containing a given STRING:
Find: β^.*STRING.*$β
Replace: ββ
This works fine and the entire line is deleted, however the blank line remains, how to delete that so that the line below comes up as in xlUp?
That’s easy akshayee,
To remove blank lines you may:
Find: \n\n
Replace: \n
Or directly:
Find: “^.*STRING.*\n”
Replace: “”
π
Hi Kedar,
You are really helpful. Thanks for your efforts.
Can you please explain us how to do the following?
Example:
Sample one
Sample two
Sample three
(having more than 20,000 lines)
I need to replace as below
Sample one
go
Sample two
go
Sample three
go
Can you please help me?
Thanks.
Hey Sathya,
Good you contacted by mail π
BTW for records:
Find: \n
replace: \ngo\n
I was hoping you could help me with this issue
Original line:
$427SCANN.HECSB-DGSESC.CAMPUS
New Line:
$427SCANN.HECSB-DGSESC.CAMPUS
changetype: modify
replace: uid
uid: $427SCANN
I need to grab the first portion of the line to the first dot, keep the original line, add the 3 new lines and add the captured first portion to uid:.
Hope you can help.
Hey McDrom,
Sorry for delayed response but here is the answer:
Find: (.*)\.(.*)\.(.*)
Replace: \1.\2.\3\nchangetype: modify\nreplace: uid\nuid: \1
Cheers…
Hey Kedar,
i want add a quote ‘ in the beginning of a word and end of word , how can i do it in edit plus
Hi Divya,
I’m not sure if that’s a single word or for each word but I’d give you an example and that should suffice your needs:
1) Replace at the beginning of the line:
Find: “^”
Replace: “`”
2) Replace after word ends
Find: “([0-9A-Za-z]) ”
Replace: “\1` ”
3) Replace at the end:
Find: “\n”
Replace: “`\n”
* Ignore double quote (“) and note the spaces.
Hope this helps…. cheers.
Hi Kedar, Could you help me?
IΒ΄m using EditPlus to modify some TXT files;
I have this info on those TXT files:
Fri Jul 19 02:13:01 CDT 2013
Usage: 370868224
Fri Jul 19 02:18:00 CDT 2013
Usage: 370868224
Fri Jul 19 02:23:00 CDT 2013
Usage: 370868224
Fri Jul 19 02:28:00 CDT 2013
Usage: 370868224
And I need to that info in this format:
Fri Jul 19 02:13:01 CDT 2013 Usage: 370868224
Fri Jul 19 02:18:00 CDT 2013 Usage: 370868224
Fri Jul 19 02:23:00 CDT 2013 Usage: 370868224
Fri Jul 19 02:28:00 CDT 2013 Usage: 370868224
Could you tell me, how can I do that change using editplus?
Thanks & regards.
Hey Eric,
Not sure how did I miss this but still the answer to this is easy:
Find: “\nUsage”
Replace: “Usage”
Apologies for hell lot of delay but hope this helps some other time. π
Hi ,
I want to add differnt numbers in last of each line i edit plus .Can any one help me to do this.
For Esxample :
I have 2 line in Edit plus:
1. India is my country
2. I love my COuntry
Now i want to put 6 in last of first line and 8 in end of second line.How we will do it in edit plus
Hey Anil,
You cannot replace individual lines with different number from single regex. I’ll still tell you how to put something at the end of the line.
Find: “$”
Replace: “6”
OR
Find: “\n”
Replace: “6\n”
Hope this helps.
Hi guys, I need to copy data in matched strings from a file which contains million of records.
ex : 1St record –> a,b,c,d,_bb_vid:CKDGJKJDGDG~~~,e,f,g
2nd record –> b,x,y,z,_bb_vid:KSDLGFMDSLKJGKD~~~,k,l,g
like this i have n no of records in a file. here the field seperator is , i need to copy the date between the matched strings “_bb_vid:” and “~~~” into another file.
please help on this.
Hi Siva,
If you can open this in EditPlus (or any editor allowing regular expressions) then you can:
Search for: “.*_bb_vid(.*)~~~.*
Replace: \1
If you’ve files in Linux:
cat filename | awk -F “_bb_vid” ‘{print $2}’ | awk -F ‘~~~’ ‘{print $1}’ > output_dates_file
Let me know.
Pingback: Search with regular expressions in Edit Plus | MyCodeKit
hello kedar, i got problem with website making. could you help me out if you know.
You can reach-out using the Community chat window or the email mentioned in contact form. BTW I can help if you’re stuck some where!
Hi how to replace this line using regex
‘Club Ties’
to
Club Ties
how to remove opening and closing quotations using regex mode
Hi Ravi,
Find: ^'(.*)’\n
Replace: \1\n
Thank you Kedar for this write up and I’ve bookmarked the page! I’m scratching my head on how to do this, and would be very grateful if you knew a way to do this.
I need to remove 2 consecutive underscores when followed by a specific string (“defaultDescription”) and replace with a single space. Also after the same string, need to remove 1 underscore and replace with a single space. This change must only be done after the string.
Example:
changed to
However, this pattern must not follow through everywhere.
Example of line that must not change:
Apologies, my examples were not published for some reason.
Example of the 2 consecutive underscores:
descriptions defaultDescription=”Posting Amount__FY_PY”
should be changed to
descriptions defaultDescription=”Posting Amount FY PY”
Example of line that should not be changed:
measure id=”POSTING_AMT__FY_PY” order=”66″ aggregationType=”sum” measureType=”simple”
Hi Michael,
Apologies for not reverting back earlier. For the problem you shared:
Find: (.*)defaultDescription(.*)\_\_(.*)\_(.*)
Replace: \1defaultDescription\2 \3 \4
You might want to make sure that only quoted strings get replaced then you can have additional:
Find: (.*)defaultDescription(.*)\”(.*)\_\_(.*)\_(.*)\”
Replace: \1defaultDescription\2″\3 \4 \5″
If you cannot guarantee the “_” occurrances etc then it’d be better to do that in two attempts. Replace __ first and then _.
Hope this helps.
hi, i have below lines like
acctInfo.setPaymentFlag(rs2.getString(“PAYMENT_FLAG”));
acctInfo.setAccountCode(rs2.getString(“ACCOUNT_CODE”));
acctInfo.setAccountName(rs2.getString(“FIRST_NAME”));
i want to get as mentioned below
PAYMENT_FLAG
ACCOUNT_CODE
FIRST_NAME
kindly help in this
Hi Rama:
Find: .*getString\(\”(.*)\”.*
Replace: \1
Cheers π
Nice article and I just saw this post ( 3 years old :D), if you still haven’t had a chance to get an answer for this, you can then try with look-ahead process.
Find: ^((?!string).)*$
replace:null
and then do \n\n replace with \n to remove empty lines
Tanks for commenting such an old article Prasenna ! I’m glad most of it still make sense π
If you’re trying to answer “Remove lines not containing a given STRING:”, please try that in EditPlus as may be you can get this working in other editors but doesn’t work in EditPlus.
Let me know,
Kedar.
Strange, I tried it in Editplus 4.0 and it works for me.
Remove Lines That does not have “test”:
==========================================
Here I have test
No search text here
this line should be removed as well
Not this line, because it has test
Test here too
1234567890
abcdefghijklmn
Search and replace:
===================
Find What: ^((?!test).)*$
Replace: “” —> null, remove quotes
Result:
=====
Remove Lines That does not have “test”:
Here I have test
Not this line, because it has test
Test here too
Hmm thanks for posting Prasenna, alas this doesn’t work in v3.51.
I can’t seem to figure this out.
say I have a data of code in the middle of other random data.
random data random code more random data
How would I remove all data between and including and
Thanks for any help.
sorry the forum stripped my code
I can’t seem to figure this out.
say I have a data of code in the middle of other random data.
random data random code more random data
How would I remove all data between and including and
Thanks for any help.
Thanks for the great help. You made my work so easy.
Thanks once again.
HI,
Iam using editplus,in this when i press space button it is showing dot at before of everyword,could anybody help me plz,how can i remove the dots.
eg:version:(dot)(dot)(dot)1
Too late to answer i guess! Did you find your answer? Did you somehow messed up in your space charter settings somewhere? care to share?
Regards.
Need a help, How to increment a number in Edit plus ? Reg ex replace ?
Hi Priya!
Did you know if Editplus has “Column Editor” in the edit menu? You can select the numeric column using ALT and use the column-editor for increment. I saw few stackoverflow answers but couldn’t confirm if that works. (Eg http://stackoverflow.com/questions/12941362/is-it-possible-to-increment-numbers-using-regex-substitution)
Best of luck for your tries and share if you find the answer.
Regards,
Kedar.
I need to delete all characters between two (2) known strings. and (I have hundreds of HTML pages with hundreds of instances on each page… please HELP!)
Example:
FIND: #footnote15 misc characters not[ always the () same 12
REPLACE: Everything between the ” and the ”
I can easily search and replace the leftover “” later.
(Let me try this again… <sup> and </sup> Characters were omitted in my first post!)
I need to delete all characters between two (2) known strings. <sup> and </sup> (I have hundreds of HTML pages with hundreds of instances on each page… please HELP!)
Example:
FIND: <sup> #footnote15 misc characters not[ always the () same 12 </sup>
REPLACE: Everything between the ‘<sup>’ and the ‘</sup>’
I can easily search and replace the leftover “<sup></sup>” later.
Not sure exactly but see if this is what you want:
Find: .*\r\n
Replace:
If \r\n doesn’t work, try with only \n
If not, share more.
Cheers.
How do I replace SOH i.e. CHAR(1) with ‘|’ in Editplus ?
thanks
Edit+ version 3.12
How to replay SOH (Start of Heading) character i.e. ASCII – 1 with Pipe (|) in Editplus ? Do I need to use Regex ?
thanks
Hello,
i have a list of thousands line like this:
some text here some other text here
some text here some other text here
some text here some other text here
some text here some other text here
Is there a way to delete the codes between the “” “” to obtain this?
some text here some other text here
some text here some other text here
some text here some other text here
some text here some other text here
how can i random lines with regex ?
ex:
1
2
3
4
5
6
7
and i want to be anything random like
4
2
1
7
…..
Hi ..First of all thanks for the beautiful articles on Edit Plus .
I want to autoconvert the case for sql syntax
Like SeleCT * from
if I write like something above it should be autocased to
SELECT * FROM as SELECT and from are the keywords