Here is a regex solution. I have provided several test cases which are intended to help you specify your real requirements. (The 'description' field tells what is special about each string.) I have assumed that by 'number', you mean 'unsigned integer'.
use strict; use warnings; use Test::Simple tests=>7; my $NUMBER = qr/[1-9]\d*/; # Unsigned integer sub solution { return $_[0] =~ s! ($NUMBER:$NUMBER): !$1//!xr; } my @test_cases = ( #given expected description ['3:4:', '3:4//', 'minimal'], ['3:4:5:', '3:4//5:', 'begining of string'], ['foo:fum3:4:', 'foo:fum3:4//', 'end of string'], ['3456:7890:5:', '3456:7890//5:', 'big integers'], ['a:b:', 'a:b:', 'no number'], ['3:4foo:', '3:4foo:', 'misplaced colon'], ['3456:0890:a:', '3456:0890:a:', 'invalid integer'], ); foreach my $case (@test_cases) { my ($given, $expected, $description) = @$case; my $computed = solution($given); ok( $computed eq $expected, $description); }

OUTPUT,

1..7 ok 1 - minimal ok 2 - begining of string ok 3 - end of string ok 4 - big integers ok 5 - no number ok 6 - misplaced colon ok 7 - invalid integer

I encourage you to modify this solution and/or list of test cases as your requirements evolve.

Bill

In reply to Re: Breaking symmetry with a regex by BillKSmith
in thread Breaking symmetry with a regex by Anonymous Monk

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.