Kodar-lan - Text and editors Regular expression
Upcoming SlideShare
Loading in...5
×
 

Kodar-lan - Text and editors Regular expression

on

  • 402 views

A lecturea about the basics in regular expression.

A lecturea about the basics in regular expression.

Statistics

Views

Total Views
402
Views on SlideShare
402
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Kodar-lan - Text and editors Regular expression Kodar-lan - Text and editors Regular expression Presentation Transcript

  • 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)
  • 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)
  • 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)
  • 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
  • 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
  • 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
  • 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 +
  • 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 +
  • Regular expression Groups ● Extract several parts of a text at the same time ● ^(.*).(.*)$ ● (filename).(Fileextension) Lecture - Regular expression (Tim Gremalm)
  • 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)