Tim Gremalm
Developer at Conmel Data AB
Programming, Web, Databases, Windows/Linux, Servers,
Network, TCP/IP, Robotics, El...
Regular expression
●

A string that forms a searchpattern

●

The basics of regex started in the 1950's

●

Used in many U...
Common uses of regular expression
●

Match a text with a searchpattern for validation

●

Search replace (substitute) text...
Regular expression
Match literary

Special Characters


Carriage return +
Tab +

v

Vertical tab +

f

Form feed +

a

Ala...
Regular expression
Anchors
●

Position your search term

Anchors
^

End of string +
Word boundary +
Not word boundary +
St...
Regular expression
Character Classes
Character Classes

●

Specify a [class] to search for

Control character

s

White sp...
Regular expression
Quantifiers

Quantifiers
*

Lecture - Regular expression (Tim Gremalm)

1 or more, ungreedy +
0 or 1 +
...
Regular expression
Ranges

Ranges
.

Lecture - Regular expression (Tim Gremalm)

[abc]

Range (a or b or c) +
Not a or b o...
Regular expression
Groups
●

Extract several parts of a text at the same time

●

^(.*).(.*)$

●

(filename).(Fileextensio...
Links
●

http://regex101.com/ - Online regex parser

●

http://regexpal.com/ - Online regex parser

●

http://gskinner.com...
Upcoming SlideShare
Loading in...5
×

Kodar-lan - Text and editors Regular expression

384

Published on

A lecturea about the basics in regular expression.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
384
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Kodar-lan - Text and editors Regular expression

  1. 1. Tim Gremalm Developer at Conmel Data AB Programming, Web, Databases, Windows/Linux, Servers, Network, TCP/IP, Robotics, Electronics tim@gremalm.se http://tim.gremalm.se Lecture - Regular expression (Tim Gremalm)
  2. 2. Regular expression ● A string that forms a searchpattern ● The basics of regex started in the 1950's ● Used in many UNIX-tools like grep, ed, awk ● Most programming languages supports regular expressions ● Also called regex, regexp Lecture - Regular expression (Tim Gremalm)
  3. 3. Common uses of regular expression ● Match a text with a searchpattern for validation ● Search replace (substitute) text ● Syntax-highlighting in editors ● Extracting relevant parts of a text Lecture - Regular expression (Tim Gremalm)
  4. 4. Regular expression Match literary Special Characters Carriage return + Tab + v Vertical tab + f Form feed + a Alarm [b] Backspace e Escape N{name} Lecture - Regular expression (Tim Gremalm) New line + t Just enter you text like: yoursearchterm n r ● Escape Character + Named Character
  5. 5. Regular expression Anchors ● Position your search term Anchors ^ End of string + Word boundary + Not word boundary + Start of word > Lecture - Regular expression (Tim Gremalm) End of line + < bStartOfWord $ B ● Start of string + b ^StartOfLine A Z ● Start of line + End of word
  6. 6. Regular expression Character Classes Character Classes ● Specify a [class] to search for Control character s White space S Not white space d Digit D Not digit w Word W Not word xhh Hexadecimal character hh Oxxx Lecture - Regular expression (Tim Gremalm) c Octal character xxx
  7. 7. Regular expression Quantifiers Quantifiers * Lecture - Regular expression (Tim Gremalm) 1 or more, ungreedy + 0 or 1 + 0 or 1, ungreedy + Exactly 3 + 3 or more + 3, 4 or 5 + {3,5}? l* +? {3,5} ● 1 or more + {3,} [d]+ + {3} ● 0 or more, ungreedy + ?? Specify how many times a class may occur *? ? ● 0 or more + 3, 4 or 5, ungreedy +
  8. 8. Regular expression Ranges Ranges . Lecture - Regular expression (Tim Gremalm) [abc] Range (a or b or c) + Not a or b or c + Letter between a and q + Upper case letter + between A and Q + Digit between 0 and 7 + n [a-zA-Z] Passive Group + [0-7] ● Group + [A-Q] [A-E] (...) [a-q] ● a or b + [^abc] Specify a class even further (a|b) (?:...) ● Any character except new line (n) + nth group/subpattern +
  9. 9. Regular expression Groups ● Extract several parts of a text at the same time ● ^(.*).(.*)$ ● (filename).(Fileextension) Lecture - Regular expression (Tim Gremalm)
  10. 10. Links ● http://regex101.com/ - Online regex parser ● http://regexpal.com/ - Online regex parser ● http://gskinner.com/RegExr/ - Online regex parser ● http://www.txt2re.com/ - Help you build regex ● http://www.myezapp.com/apps/dev/regexp/show.ws - Help you analyze the regex-syntax in words Lecture - Regular expression (Tim Gremalm)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×