jsor
jsor

Reputation: 667

perl split and regular expressions case in-sensitve

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 ?

Upvotes: 3

Views: 104

Answers (1)

zdim
zdim

Reputation: 66883

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'

Upvotes: 4

Related Questions