in reply to Re^3: Question on Regular Expression
in thread Question on Regular Expression

Thanks for approach and I really appreciate your help on this

Although you showed me the result what I wanted but I needed something more

I guess I gave you simple example to illustrate the problem I faced. In my earlier example I used the regular expression as '(.*) (0-9) (A-Z) ((A-Z)'

I ran the code snippet you gave me for 'RW12QW1XY' and it does not work and where as expected out come is as below

'RW12QW1X' -> ("RW12QW", "1", "X", "")

Replies are listed 'Best First'.
Re^5: Question on Regular Expression
by AnomalousMonk (Archbishop) on Dec 28, 2014 at 05:57 UTC

    Please post your test code and output in something like the format shown below, and please use code tags; I can't really understand your regex without guessing! Please also give your expected/desired output; "it does not work" does not tell me very much.

    c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -e "my @test = qw(RC1XY RS RW12QW1X FOO FOOx FOO23PQ xFOO23PQXXX foo xyzz +y); ;; for my $s (@test) { printf qq{'$s' -> }; if (my ($p_r, $d1, $p_mc, $p_new_mc) = $s =~ m{ ([[:upper:]]+) (\d*) ([[:upper:]]?) ([[:upper:]]?) }xms) { dd $p_r, $d1, $p_mc, $p_new_mc; } else { print qq{no match \n}; } } " 'RC1XY' -> ("RC", 1, "X", "Y") 'RS' -> ("RS", "", "", "") 'RW12QW1X' -> ("RW", 12, "Q", "W") 'FOO' -> ("FOO", "", "", "") 'FOOx' -> ("FOO", "", "", "") 'FOO23PQ' -> ("FOO", 23, "P", "Q") 'xFOO23PQXXX' -> ("FOO", 23, "P", "Q") 'foo' -> no match 'xyzzy' -> no match


    Give a man a fish:   <%-(-(-(-<

Re^5: Question on Regular Expression
by Anonymous Monk on Dec 28, 2014 at 04:41 UTC

    You are not giving us enough information to work with. Please provide a large enough set of example inputs with their expected outputs to cover the expected combinations of actual input.

Re^5: Question on Regular Expression
by sjain (Initiate) on Dec 28, 2014 at 06:02 UTC

    Here are more example strings :

    1. Sample1Repeat1A -> ("Sample1Repeat", "1", "A", "")

    2, Sample2Repeat2 -> ("Sample2Repeat", "2", "", "")

    3. Sample3Repeat -> ("Sample3Repeat", "", "", "")

    4. 4SampleRepeat -> ("4SampleRepeat", "", "", "")

    5. 4SampleRepeat4 -> ("4SampleRepeat", "4", "", "")

    6. 5SampleRepeat5D -> ("4SampleRepeat", "5", "D", "")

    I hope these samples help giving more information.