[Purdue-pm] Regex Unification
Dave Jacoby
jacoby at purdue.edu
Mon May 16 07:32:19 PDT 2011
I have this bank of regexes in my code.
$requests2{ $request }->{ $href->{ accession_id } }
->{ library } =~ s/\W/\-/g ;
$requests2{ $request }->{ $href->{ accession_id } }
->{ library } =~ s/_/\-/g ;
$requests2{ $request }->{ $href->{ accession_id } }
->{ library } =~ s/-+/-/g ;
$requests2{ $request }->{ $href->{ accession_id } }
->{ library } =~ s/-$//g ;
I'm thinking that I can simplify this a lot.
Change the \W and _ regexes to \W+ and _+ and you reduce the need for
the s/-+/-/, so we can reduce it, I think, to
$requests2{ $request }->{ $href->{ accession_id } }
->{ library } =~ s/[\W_-]+/\-/g ;
I'd have to bash that regex before I'm comfortable putting it into
production.
But the last part, getting rid of dashes at the end of a string, can I
roll that into the bigger regex? I'm not seeing how right now.
--
Dave Jacoby Address: WSLR S049
Code Maker Mail: jacoby at purdue.edu
Purdue University Phone: 765.49.67368
1057 days until the end of XP support
More information about the Purdue-pm
mailing list