Regular Expression help

I have a string composed of three parts.

  1. a number, could be 1, 2, 3, 4 or more digits.
  2. the word pending
  3. and then a date in this format: year,month,day,hour,minute,second

I would like to extract each in a variable.

Examples:

7pending20110721170832
504pending20110720110107

On Jul 21, 2011, at 3:15 PM, Leonel . wrote:

504pending20110720110107

This is a good place to play

(\d) => capture a single digit
(\w) => capture a single letter

Very easy :slight_smile:

(\d+)(\w+)(\d{4})(\d{2})(\d{2}
)(\d{2})(\d{2})(\d{2})

Tests…

http://www.gethifi.com/tools/regex

http://nregex.com/nregex/default.aspx

2011/7/21 Leonel . [email protected]

504pending20110720110107
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Fernando A.