arunhorne has asked for the wisdom of the Perl Monks concerning the following question:
OK, heres a weird one I came across.
I have a list of chemical names; something like:
3 L-homoserine 1 L-iditol
As is the way with chemical names they have lots of synonyms and so I am replacing these with regular expressions. My problem arises because there may be an arbitrary numerator in front of the chemical name (as they came from a formula)... this needs to be preserved as the formulas will be rebuilt.
The synonym for L-iditol is L-Iditol (just a case change) so this is fine being replaced by:
s/(\d+ *)L\-iditol/\1L\-Iditol/
Simple and works... however the synonym for L-homoserine is infact 2-Amino-4-hydroxybutyric acid.
So I write the regex:
s/(\d+ *)L\-homoserine/\12\-Amino\-4\-hydroxybutyric\ acid/
When applied to L-homoserine I get a blank line then '-Amino-4-hydroxybutyric acid' (note the missing 2). Note that in the regular expression the replacement string begins \12 . The \1 bit includes the numerator (3 in the above example) but the 2 is actually part of the new string. When combined they don't work like this. I consulted by table of ascii values and find that \012 is infact the code for newline...
Has anyone had this problem before? How can I force \12 to behave as I want it rather than producing a new line?
Looking forward to resolving this strange one.
Arun
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regular expressions Containing Octal values?
by jmcnamara (Monsignor) on May 17, 2002 at 09:44 UTC | |
by arunhorne (Pilgrim) on May 17, 2002 at 10:11 UTC | |
by arunhorne (Pilgrim) on May 17, 2002 at 10:58 UTC | |
by merlyn (Sage) on May 17, 2002 at 15:24 UTC | |
by jmcnamara (Monsignor) on May 17, 2002 at 16:03 UTC | |
by merlyn (Sage) on May 17, 2002 at 16:06 UTC | |
|
Re: Regular expressions Containing Octal values?
by Zaxo (Archbishop) on May 17, 2002 at 11:23 UTC | |
by mephit (Scribe) on May 17, 2002 at 20:16 UTC | |
|
•Re: Regular expressions Containing Octal values?
by merlyn (Sage) on May 17, 2002 at 15:27 UTC |