How to use m! in perl regex

I'm learning Perl about regular expressions for the first time, so I apologize if this is a dumb question. I was looking for an answer for myself, but I can not find anything. Maybe part of my problem is that I really don't know what it's called.

I came across a piece of code that looked like this:

$xl_file = "$curr_dir/$xl_file" unless $xl_file =~ ( m!(^[az]:)|[/\\]!i ); 

When I looked into the operator = ~, I ducked into the regex hole and began to find out about it. But I just saw the matching operator "m //". I guess m! this is a different type of matching operator, but I cannot find links to it that explain how this works. Through the experiment, I see that β€œ! I” is required when using it, but this is about the way I could understand ...

Could someone explain this to me or point me in the direction of some (free) material that can?

+4
source share
2 answers

No, this is the same. In Perl, you can choose regular expression delimiters as you like. I.e

 m/foo/ /foo/ m!foo! m"foo" m+foo+ m xfoox m{foo} 

- still a regular expression (but never use question marks as a separator, they wake up an ancient demon).

After closing the delimiter, regular expression modifiers are set. The /i modifier activates case insensitivity.

For a full blast, you can dive into perlre for all hidden Perl regular expression nuggets. But for starters, perlretut should be more appropriate.

+4
source

Using the match operator, you can use any type of delimiter, not just / .

So, all of the matching operators below are valid and perform the same task:

 m// m!! m{} m## 

Also note that if you use / as a delimiter, you can remove this m from the beginning. So /foo/ valid, but !foo! is not.

+6
source

Source: https://habr.com/ru/post/1487135/


All Articles