We don't bite newbies here... much | |
PerlMonks |
Re: Howto strip 42 from comma separated list using s///by jbware (Chaplain) |
on Nov 03, 2005 at 13:23 UTC ( [id://505319]=note: print w/replies, xml ) | Need Help?? |
Is this maybe the regex that you're looking for? There may be more elegant ways, but this seems alot easier to decipher.
Update: Added the case for a single element of just "42" per Not_a_Number's and Perl Mouse's suggestions. Good catch; that's what a quick solution gets me, I didn't test all cases. I should note too, the position of 42 at the end of the list is important, so the regex engine doesn't try and grab that without looking for commas first. Update: Perl Mouse makes a good point here: 505335 on boundary checking too, so I made another mod to the regex to take that into account as well. Update: Ok, this is it; no more updates. One catch w/ boundary checking is in the odd case of "41,I like 42 things, 43", which would replace the "42", but shouldn't. I think in the context of this question this is really isn't an issue and \b works fine. To combat that though, I just hit what really was being addressed, "^42$", where its the only element. Update: lol. I give up; one more. Perl Mouse pointed out partial number matches, so the boundary checking is back in a modified form. He has this below too. I only mod it here so in case someone takes a quick glance, they can get my best version (with the help of mightier monks than I) instead of my regex version from like 4 iterations ago. -jbWare
In Section
Seekers of Perl Wisdom
|
|