Translation rules question

I'm confused about an aspect of the voice translation rule. Here is an example:

The following translation rule uses this format -

voice translation-rule 1
rule 1 /^\(35\)6\(72\)$/ /9\1\2/


In this example, a dialed string of 35672 would result in a replaced string of 93572. The 6 is not in parentheses and is ignored.


Here, in rule 1 I thought anything immediately starting with "35" was replaced with "9"? And what happened to the digits "12" at the end of rule 1? Aren't they supposed to be replacing something? Where is the "1"?
"Computers in the future may weigh no more than 1.5 tons." - Popular Mechanics, 1949

Comments

  • mikej412mikej412 Member Posts: 10,086 ■■■■■■■■■■
    You may want to review the rule (voice translation-rule) command and Voice Translation Rules -- and walk through this step by step.

    rule # /match-pattern/ /replace-pattern/
    -- so this is a match and replace rule, rather than a reject rule.

    Since there were no funky wildcards like * and/or + and no . and/or ? in the match-pattern -- this is an "easy one." :D
    /^\(35\)6\(72\)$/
    The ^ is match from the beginning of the string
    The () indicates what to keep.
    The \ indicates where to "slice the number"
    So from the beginning of the match-pattern the first 2 digits should be 35 and we want to keep them, so set match string 1 to 35
    The match pattern must have the digit 6 in the 3rd position
    And the match-pattern should have 73 in the next 2 positions (4 and 5) and we want to keep them, so set match string 2 to 72
    The $ is the end of the string -- so we're matching exactly the 5 digit string 35672

    So, if the input pattern matches 35672, then replace it with.....
    /9\1\2/
    Put in the digit 9 in the first position.
    The \1 says to put the 1st saved string from the match here -- that is the 35
    The \2 says to put the 2nd saved string from the match here -- that is the 72
    And that's it for the replace

    So if you start with 35672, after translation you'd get 93572
    :mike: Cisco Certifications -- Collect the Entire Set!
  • CrunchyhippoCrunchyhippo Member Posts: 389
    Thanks for the help.

    Do you know if there might be a place online where one can practice these - particularly the number slices?
    "Computers in the future may weigh no more than 1.5 tons." - Popular Mechanics, 1949
  • mikej412mikej412 Member Posts: 10,086 ■■■■■■■■■■
    The best place to practice is on a voice router. Create the translation rules and then use the test translation-rule command to try them out.

    The 2nd link has examples you can start with -- then try modifying them. Toss in some wildcards to make them more interesting. Then try multiple rules.
    :mike: Cisco Certifications -- Collect the Entire Set!
  • CrunchyhippoCrunchyhippo Member Posts: 389
    mikej412 wrote:
    The best place to practice is on a voice router. Create the translation rules and then use the test translation-rule command to try them out.

    The 2nd link has examples you can start with -- then try modifying them. Toss in some wildcards to make them more interesting. Then try multiple rules.

    I think I've got most of it now; however, I have an example or two here that are throwing me, as they don't seem to be conforming to the rules. For example:

    rule 1 /^589\(.*\)/ /555\1/

    The dialed string is: 5891672

    The replaced string value is: 5891672


    The 589 goes first, since it's preceded by a carat - I get that. Positon 1 is next, which is (.*\) and is anything - in this case, it's 1672. So you get 5891672.


    Next example is where I'm confused:

    rule 2 /^\(289\)\(....\)/ /601\2/

    The dialed string is: 2896438

    The replaced string value is: 6016438


    Now, this example is very similar to the other one; in the replace string on the first one, the 589 goes first, since it's followed by the ^ in the match string; but in the second example, the 289 is preceded by the ^, also, but the 601 is first. Why? The 289 is preceded by the ^ like the last one, and the dialed string begins with 289. ??

    Addendum: Ok, I do see a difference in the two - the first one is /^589\
    the second one is /^\(289\)

    Evidently, if a number preceded by a ^ isn't in parenthesis, it goes first in the string as long as it's first; if a number preceded by a ^ is in parenthesis, the (in this case) first number in the replace string goes first. icon_mad.gif Had to figure it out the hard way.
    "Computers in the future may weigh no more than 1.5 tons." - Popular Mechanics, 1949
  • mikej412mikej412 Member Posts: 10,086 ■■■■■■■■■■
    Evidently, if a number preceded by a ^ isn't in parenthesis, it goes first in the string as long as it's first; if a number preceded by a ^ is in parenthesis, the (in this case) first number in the replace string goes first. icon_mad.gif Had to figure it out the hard way.
    Not on my router icon_confused.gif
    rule 1 /^589\(.*\)/ /555\1/

    The dialed string is: 5891672

    The replaced string value is: 5891672


    The 589 goes first, since it's preceded by a carat - I get that. Positon 1 is next, which is (.*\) and is anything - in this case, it's 1672. So you get 5891672.

    Rule 1 matches the beginning 589 -- but it DOES NOT get placed in the replacement string.
    Matched with rule 1
    Original number: 5891672
    Translated number: 5551672


    Router#show voice translation-rule
    Translation-rule tag: 100
    
            Rule 1:
            Match pattern: ^589\(.*\)
            Replace pattern: 555\1
            Match type: none                Replace type: none
            Match plan: none                Replace plan: none
    
            Rule 2:
            Match pattern: ^\(289\)\(....\)
            Replace pattern: 601\2
            Match type: none                Replace type: none
            Match plan: none                Replace plan: none
    
    Router#test voice translation-rule 100 5891672
    Matched with rule 1
    Original number: 5891672        Translated number: 5551672
    Original number type: none      Translated number type: none
    Original number plan: none      Translated number plan: none
    
    Router#test voice translation-rule 100 589167299999
    Matched with rule 1
    Original number: 589167299999   Translated number: 555167299999
    Original number type: none      Translated number type: none
    Original number plan: none      Translated number plan: none
    
    Router#test voice translation-rule 100 2896438
    Matched with rule 2
    Original number: 2896438        Translated number: 6016438
    Original number type: none      Translated number type: none
    Original number plan: none      Translated number plan: none
    
    Router#test voice translation-rule 100 2896438999999
    Matched with rule 2
    Original number: 2896438999999  Translated number: 6016438999999
    Original number type: none      Translated number type: none
    Original number plan: none      Translated number plan: none
    
    Router#
    
    :mike: Cisco Certifications -- Collect the Entire Set!
  • CrunchyhippoCrunchyhippo Member Posts: 389
    By George - you're right! icon_idea.gif I know I put that number right in the router in the lab. At least this shows me clearly now how slicing works. I would have messed things up royally by depending on faulty info. Blasted routers!

    I tip my hat. icon_thumright.gif
    "Computers in the future may weigh no more than 1.5 tons." - Popular Mechanics, 1949
Sign In or Register to comment.