>>>>> "ponnambalam" == ponnambalam ma <[EMAIL PROTECTED]> writes:
> DEAR FRIENDS,
> PLEASE HELP ME REGARDING THE REGULAR EXPRESSION IN SPLIT FUNCTION
> data is : CDM210909 or FDM210909 ( ie start with 3characters followed
> any no of numeric numbers)
> probelm is : i need to split this word into CDM and 210909 ( split into
> characters & numbers).
> --- ie, i wish to split this word into char (first 3 characters & remaining
> )
> @res=split( / .{3}/ , $data );
If you are not attached to split(), I would recommend something like this:
$a = 'CDM210909';
$a =~ /([A-Z]{3})([0-9]+)/;
$chars = $1;
$numbers = $2;
If your string might include lowercase as well, then use:
$a =~ /([A-Za-z]{3})([0-9]+)/;
As with any regular expression, I test it out first by typing:
$ perl -de 0
at the command prompt, at which point you can just type in perl
expressions and print them out. Here is the sample session I did to
test this regex out (my input is after the DB<n> lines):
sys_test> perl -de 0
Default die handler restored.
Loading DB routines from perl5db.pl version 1.07
Editor support available.
Enter h or `h h' for help, or `perldoc perldebug' for more help.
main::(-e:1): 0
DB<1> $a='CDE43243243'
DB<2> p $a
CDE43243243
DB<3> $a=~/([A-Z]{3})([0-9]+)/;$b=$1;$c=$2
DB<4> p $b
CDE
DB<5> p $c
43243243
DB<6> q
sys_test>
In step <3>, you need to place the three statements on one line since
the debugger does not seem to 'remember' them if they are on separate
lines. Hope this helps.
Sarir
_______________________________________________
Perl-Unix-Users mailing list. To unsubscribe go to
http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users