the power of regular expression: use in notepad++
DESCRIPTION
TRANSCRIPT
![Page 1: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/1.jpg)
A look at the power of Regular Expressions
for the layman
Use in Notepad++
Anjesh Tuladharhttp://anjesh.blogspot.com
http://just-tech.blogspot.com
![Page 2: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/2.jpg)
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
![Page 3: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/3.jpg)
Remove numbers from the list of 1000 rows of names
![Page 4: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/4.jpg)
Choose “Replace” from “Search” menu
![Page 5: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/5.jpg)
You will get a replace dialog box.
![Page 6: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/6.jpg)
Type [0-9]* (.*) in find what box, \1 in replace with box. Note: There’s a space between [0-9]* and (.*).
![Page 7: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/7.jpg)
Check Regular Expression checkbox to exploit regex functionality.
![Page 8: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/8.jpg)
Hurray! Done.
![Page 9: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/9.jpg)
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
![Page 10: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/10.jpg)
Now you have to swap numbers and names, but separated by comma.
![Page 11: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/11.jpg)
Type ([0-9]*) (.*) in find what box, \2,\1 in replace with box.
![Page 12: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/12.jpg)
Replaced!
![Page 13: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/13.jpg)
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
![Page 14: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/14.jpg)
Now you have to remove numbers, put last-name first, followed by first-name, and separated by comma.
![Page 15: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/15.jpg)
Type ([0-9]*) ([^ ]*) (.*) in find what box, \3,\2 in replace with box.
![Page 16: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/16.jpg)
Replaced!
![Page 17: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/17.jpg)
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
![Page 18: The Power of Regular Expression: use in notepad++](https://reader036.vdocuments.net/reader036/viewer/2022081413/5486ea43b47959050d8b53ab/html5/thumbnails/18.jpg)
The beginning
Make today
a noble beginning
with The Regular Expressions