[tpm] Regex question

tiger peng tigerpeng2001 at yahoo.com
Tue Jul 8 19:44:46 PDT 2008


Two efficient ways

1. Using anchor ($) to make it match faster
-> perl -le '$foo="ABC-987-01"; $bar=$foo; $bar =~s/-\d+$//;print $bar'
ABC-987

2. Using non-regex.
-> perl -le '$foo="ABC-987-01"; print substr($foo, 0, rindex($foo, "-"))'
ABC-987
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20080708/e3008456/attachment.html>


More information about the toronto-pm mailing list