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


In reply to Regular expressions Containing Octal values? by arunhorne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.