The Power of Regular Expression: use in notepad++

18
A look at the power of Regular Expressions for the layman Use in Notepad++ Anjesh Tuladhar http://anjesh.blogspot.com http://just-tech.blogspot.com

description

 

Transcript of The Power of Regular Expression: use in notepad++

Page 1: 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

Page 2: The Power of Regular Expression: use in notepad++

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++

Remove numbers from the list of 1000 rows of names

Page 4: The Power of Regular Expression: use in notepad++

Choose “Replace” from “Search” menu

Page 5: The Power of Regular Expression: use in notepad++

You will get a replace dialog box.

Page 6: The Power of Regular Expression: use in notepad++

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++

Check Regular Expression checkbox to exploit regex functionality.

Page 8: The Power of Regular Expression: use in notepad++

Hurray! Done.

Page 9: The Power of Regular Expression: use in notepad++

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++

Now you have to swap numbers and names, but separated by comma.

Page 11: The Power of Regular Expression: use in notepad++

Type ([0-9]*) (.*) in find what box, \2,\1 in replace with box.

Page 12: The Power of Regular Expression: use in notepad++

Replaced!

Page 13: The Power of Regular Expression: use in notepad++

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++

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++

Type ([0-9]*) ([^ ]*) (.*) in find what box, \3,\2 in replace with box.

Page 16: The Power of Regular Expression: use in notepad++

Replaced!

Page 17: The Power of Regular Expression: use in notepad++

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++

The beginning

Make today

a noble beginning

with The Regular Expressions