perl split and regular expressions case in-sensitve

Viewed 53

I have a have a string where the seprator is word and is case insenstive something like this

Data1 sep Data2 Sep date 3 SEP Data4 SeP Data 5

i am writing something like this :

split /(sep|SEP|Sep|seP)/, $string

is there an option to list split to split data incase sensitve ?

1 Answers

The first argument in split, for the separator, is a normal regex so

my $sep = 'sep';

my @fields = split /$sep/i, $string;

will split the string by sep case-insensitively (on any of sep, sEP, etc).


Easy try:

perl -wE'$str = q(heysephosEpho); say for split /seP/i, $str'
Related