Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

escape character in regex

1 view
Skip to first unread message

Henrik Park

unread,
Oct 10, 2022, 9:30:05 PM10/10/22
to begi...@perl.org
Hello

I know "/" is a special character for regex, which should be escaped.

But if I put "/" in a variable and use the variable in regex, then it
doesn't need the explicit escape. Like this one:

$ perl -le '$delimiter="/"; $str="hello/world/buddy";
@list=split/$delimiter/,$str;print "@list"'
hello world buddy


Am I right? thank you.


--
Simple Mail
https://simplemail.co.in/

Henrik Park

unread,
Oct 10, 2022, 10:00:06 PM10/10/22
to begi...@perl.org
John,

for my this code:

my $delimiter = '$';
my $str = 'hello$world$buddy';
my @li = split/$delimiter/,$str;
print "@li","\n";

How can I make it work correctly?

Thanks

John W. Krahn wrote:
> "/" is NOT a special charater in a regular expression.  It is just that
> in Perl the default delimiter for some operators is "/" (i.e. m//, s///,
> tr///, etc.).
0 new messages