The Power of Regular Expression: use in notepad++
-
Upload
anjesh-tuladhar -
Category
Technology
-
view
243.529 -
download
2
description
Transcript of The Power of Regular Expression: use in notepad++
A look at the power of Regular Expressions
for the layman
Use in Notepad++
Anjesh Tuladharhttp://anjesh.blogspot.com
http://just-tech.blogspot.com
Alert
• Don’t expect to master regular expressions (regex) in this short presentation. • This shows how you can exploit regex to make your
work a breeze• It takes a lot of time and hard work to learn regex
• You don’t have to be a programmer to master regular expressions, though being a programmer is definitely a plus point
Remove numbers from the list of 1000 rows of names
Choose “Replace” from “Search” menu
You will get a replace dialog box.
Type [0-9]* (.*) in find what box, \1 in replace with box. Note: There’s a space between [0-9]* and (.*).
Check Regular Expression checkbox to exploit regex functionality.
Hurray! Done.
A short explanation
• [0-9]* will match numbers only• In our case it matches numbers only
• .* will match any characters, including numbers till the end of the line• Use of the curve brackets will act as a memory• Enclosing .* with brackets like (.*) will allow to access it
using \1 (see in the replace box)
• The space between [0-9]* and (.*) represents the actual space between numbers and the names in the list
Now you have to swap numbers and names, but separated by comma.
Type ([0-9]*) (.*) in find what box, \2,\1 in replace with box.
Replaced!
A short explanation
• See previous explanation for [0-9]* and (.*)• Now enclosing [0-9]* with curve brackets will
allow to access it • First curve bracket can be accessed using \1 and
second can be accessed using \2• Hence we are swapping the position of names and
numbers
Now you have to remove numbers, put last-name first, followed by first-name, and separated by comma.
Type ([0-9]*) ([^ ]*) (.*) in find what box, \3,\2 in replace with box.
Replaced!
A short explanation
• [0-9]* will match numbers only• [^ ]* will match anything from the current
position till it finds space, which in our case will match the first-names only
• .* will match any character from the current position till the end of the line
• Now [0-9]* is accessed using \1, [^ ]* is accessed using \2 and .* is access using \3, since all of those expressions are enclosed with curve brackets
The beginning
Make today
a noble beginning
with The Regular Expressions