Hi, This is also my first time posting with the Monks, so please let me know if I'm not following the guidelines as well.
I have two regex questions. First, when you're using s/// can you have multiple options for replacing text? I saw that you could do this with a hash array but was looking for just a regex solution if possible.
For instance, I have text such as
oldsmobile_eighty_eight
oldsmobile_ninety_nine
which I'd like to replace with
olds_88
olds_99
I was looking for something similar to translate (but for longer strings instead of individual letters) where I could say change 'eighty eight' to 88 and 'ninety_nine' to 99 if 'oldsmobile' is matched.
My second question is about using capturing with the lookahead. Again I'm looping over vehicle names and would like to get rid of text around a vehicle name, and keep they hybrid designation if it exists. For example,
k1500_silverado_xfe_hybrid_2wd would become silverado_hybrid
and
k1500_silverado_awd would become silverado
I had tried a few different configurations, such as
s/^.*(silverado|sierra)(.*?)((_hybrid)?)(.*)/$1$3/gito throw out stuff between the model name and 'hybrid' if it exists. I tried using regex like
.*(?!_hybrid) but don't know how to make it work for all cases whether it's a hybrid or not.
Thanks for your help.
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.