Hi, I'm just coming to terms with regex in Perl and have been looking a a problem using Perl. I have a solution but it looks a bit clunky to me and I wonder if some Perl experts can cast there eye over it and suggest ways of improving the regex I've created. Your help is appreciated.
I have several words I need to match when a user inputs some data. The format of the words are as follows
CDC_(followed by any number of alphanumeric characters)_(followed by any number of alphanumeric characters)
DDCSMR(followed by any number of alphanumeric characters)
DDCRMR (followed by any number of alphanumeric characters)
e.g. CDC_ABCTST_NUM1, DDCSMR12AFT, DDCRMRXX5Z1
all characters are upper case . The words all have the same format *_*_* or DDCRMR* or DDCSMR*
here is the code
#!/usr/bin/perl
use warnings;
use strict;
while(<>) {
if(m/\bSYB_([A-Z])+_([A-Z0-9])+\b|\b(ASESMR|ASERMR)([A-Z0-9])+\b/) {pr
+int "Found a match $_\n";}
}
This matches the words but I can't help thinking it could be improved upon.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.