in reply to Re: Phone number to word conversion
in thread Phone number to word conversion

That doesn't work unless the entire string matches a word. So, if you had a number (to use your example) of 967-5355, "world" would be a valid substring within it - but your "grep" line, above, wouldn't show it. Which was the whole reason for my initial post. :)


--
"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf

Replies are listed 'Best First'.
Re^3: Phone number to word conversion
by aquarium (Curate) on Nov 12, 2010 at 03:47 UTC
    if you also want substring matching..merely remove the start and end anchors in the regex. if you instead want all permutations of the number (digits in any order) mapping onto words, it's a little more complicated.
    the hardest line to type correctly is: stty erase ^H
      in the end you will find that you have to come up with a very fine specification for what is and isn't acceptable during your mapping, as those choices will substantially influence technique. for example you could also want any number of letters in any permutation, as long as there's at least one or more of a particular digit. The digit 1 could be used as a wildcard, etc, etc. The most straightforward case--what does my full phone number spell as an entire word in that sequence--is a very easy regex.
      the hardest line to type correctly is: stty erase ^H

        > you have to come up with a very fine specification for what is and isn't acceptable during your mapping

        I don't mean to sound insulting, but I did come up with one. Please take a careful look at the original post.


        --
        "Language shapes the way we think, and determines what we can think about."
        -- B. L. Whorf

      > if you also want substring matching..merely remove the start and end anchors in the regex.

      I'm sorry, you seem to have conflated the string and the regex. That won't work; it's equivalent to saying that /foobar/ will match "ooba" because there aren't any anchors in it. The problem is quite a bit more complicated than that; please take a look at both the specification in my original post and JavaFan's solution, which addresses it perfectly.


      --
      "Language shapes the way we think, and determines what we can think about."
      -- B. L. Whorf