hankcoder has asked for the wisdom of the Perl Monks concerning the following question:
Hi I'm new here. I had search days on the task I want to perform but I don't know what exactly it is called and can't find it so I have to ask for help.
Task: To split a string into equal fixed characters using regex
Problem: Modify current regex so result would appear in reverse order as "111-111-1" instead "1-111-111".
I prefer to use regex, not to use reverse function.
I couldn't remember where exactly I found below regex before, it works perfectly. Only now I want to make another version out of it so I can perform as I mentioned above.
$line =~ s/(?<=\w)(?=(?:\w\w\w)+\b)/-/g;--- Perl sample codes ----- my (@list) = ( "12", "123", "1234", "12345", "123456", "1234567", "234", "2345", "23456" ); foreach $line (@list) { $line =~ s/(?<=\w)(?=(?:\w\w\w)+\b)/-/g; print "$line<br>"; }
--- results of above code 12 123 1-234 12-345 123-456 1-234-567 234 2-345 23-456
I want it appear as:
123-4 123-45 123-456 123-456-7
Many thanks in advance.
|
|---|