Regular Expression (regex) - Forsiden

[Pages:44]Regular Expression (regex)

Jonathan Feinberg Dept. of Informatics, Univ. of Oslo

Simula Research Laboratory

August 2014

Regular expression (regex)

Regular expression (regex) ? p.1

Contents

Motivation for regular expression Regular expression syntax Lots of examples on problem solving with regular expressions For more information on regex in Python:

doc/texts/pub/pyregex.html

Regular expression (regex) ? p.2

Digression: Editor war!

Digression: Editor war! ? p.3

Regular expression is advanced search and replace

It is strongly ecourage to learn by experimenting in a supported editor.

Emacs

?q=emacs+tutorial

Vim

$ sudo apt-get install vim-gnome # or vim-gtk or vim-common

$ vimtutor

# 30 minutes to learn basic stuff

Sublime



Notepad++ (Windows)



textmate (Mac)



Digression: Editor war! ? p.4

Regex search and replace in Emacs and Vim

Emacs search:

C-M-s

M-x isearch-forward-regex

Emacs replace:

C-M-%

M-x replace-regexp

# [y]es/[n]o/all[!]/cancel[]

Vim highlighting:

:set hls

:set hlsearch

Vim search:

/\v

Vim replace:

:%s/\v

Digression: Editor war! ? p.5

Show and tell

Show and tell ? p.6

The command line wild card

Consider a simulation code with this type of output:

$ ls *.tex report.tex

Here '*' is a wild card and can be read as: "Zero or more of any non-linefeed character type". Simple and powerful, but some what unrefined.

Show and tell ? p.7

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download