We Recommend

Programming in Objective-C Programming in Objective-C
Programming in Objective-C is a concise, carefully written tutorial on the basics of Objective-C and object-oriented programming. The book makes no assumption about prior experience with object-oriented programming languages or with the C language (upon which Objective-C is based). And because of this, both novice and experienced programmers alike can use this book to quickly and effectively learn the fundamentals of Objective-C.


Posted By

hansamann on 02/02/07


Tagged

regex regular expressions groovyseries


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

jsbournival


Groovy Series: Regular Expressions 3/3


Published in: Groovy 


URL: http://hansamann.podspot.de/files/grails_podcast_episode_32_1036.mp3

  1. //pattern examples. Creating a time pattern that can be reused.
  2. def timePattern = ~/\d\d:\d\d/
  3.  
  4. def timeString = "Between 06:00 and 10:00, most geeks are asleep."
  5. def matcher = timePattern.matcher(timeString)
  6. def times = []
  7. matcher.each { times << it }
  8. assert times.join(", ") == '06:00, 10:00'
  9.  
  10. def anotherTimeString = "But between 22:00 and 02:00, most geeks are awake"
  11. //we reuse the pattern
  12. matcher = timePattern.matcher(anotherTimeString)
  13. times = []
  14. matcher.each { times << it }
  15. assert times.join(", ") == '22:00, 02:00'

Report this snippet 

You need to login to post a comment.