Re: escape character in regex

2022-10-10 Thread John W. Krahn

On 2022-10-10 18:12, Henrik Park wrote:


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.




"/" 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.).


John

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




escape character in regex

2022-10-10 Thread Henrik Park

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/

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/