Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

# Saving this for later?

### Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Standard text messaging rates apply

# Basic Regular Expressions

117
views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
117
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
4
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. Regular Expressions What are they and what can they do for you?Thursday, February 7, 13
• 2. b[A-Z0-9._%+-]+@[A- Z0-9.-]+.[A-Z]{2-4}b Source: http:/ /www.regular- expressions.info/email.htmlThursday, February 7, 13
• 3. So...what is a regular expression?Thursday, February 7, 13
• 4. A Regular Expression is a pattern for a string.Thursday, February 7, 13
• 5. What can you do with Regular Expressions? Test a string Extract a string Change a stringThursday, February 7, 13
• 6. Creating Regular Expressions /RegularExpression/Thursday, February 7, 13
• 7. Scenario #1 Testing StringsThursday, February 7, 13
• 8. Examples from “Programming Ruby” (PickAxe)Thursday, February 7, 13
• 9. “dog and cat”Thursday, February 7, 13
• 10. “dog and cat” /cat/Thursday, February 7, 13
• 11. “dog and cat” /cat/ /cat/ =~ “dog and cat”Thursday, February 7, 13
• 12. =~ /cat/ =~ “dog and cat”Thursday, February 7, 13
• 13. Thursday, February 7, 13
• 14. Thursday, February 7, 13
• 15. match /cat/.match(“dog and cat”)Thursday, February 7, 13
• 16. Valid EmailsThursday, February 7, 13
• 17. thing@thing.thingThursday, February 7, 13
• 18. RubularThursday, February 7, 13
• 19. Alternation /Nell | Brandon/Thursday, February 7, 13
• 20. . Metacharacters any single character character can appear * any number of timesThursday, February 7, 13
• 21. /.*/ matches ANYTHINGThursday, February 7, 13
• 22. Range [a-d] [1-4]Thursday, February 7, 13
• 23. Shorthand! w stands for any word character. It’s the same as: [a-zA-Z0-9_]Thursday, February 7, 13
• 24. Metacharacters + character occurs one or more timesThursday, February 7, 13
• 25. Thursday, February 7, 13
• 26. Scenario #2 Extracting StringsThursday, February 7, 13
• 27. Shorthand! d stands for any digit D stands for any non- digitThursday, February 7, 13
• 28. Repetition! d{3} Looks for exactly 3 digitsThursday, February 7, 13
• 29. Make It Optional! ? Makes a character optional. It can occur 0 or 1 time.Thursday, February 7, 13
• 30. Scenario #3 Changing StringsThursday, February 7, 13
• 31. “Brandon is the teacher of the class right now. Brandon is teaching about regular expressions.”Thursday, February 7, 13
• 32. sub(/pattern/, “text”)Thursday, February 7, 13
• 33. gsub(/pattern/, “text”) (replace ALL the matches)Thursday, February 7, 13
• 34. sub and gsub create new strings. sub! and gsub! change the original stringsThursday, February 7, 13
• 35. Welcome to the wonderful world of Regular Expressions!Thursday, February 7, 13