How to match string that contain exact 3 time occurrence of special character in perl

前端 未结 4 445
梦谈多话
梦谈多话 2021-01-20 13:40

I have try few method to match a word that contain exact 3 times slash but cannot work. Below are the example

@array = qw( abc/ab1/abc/abc a2/b1/c3/d4/ee w/5         


        
4条回答
  •  悲哀的现实
    2021-01-20 14:40

    You need to match

    • a slash
    • surrounded by some non-slashes (^(?:[^\/]*)
    • repeating the match exactly three times
    • and enclosing the whole triple in start of line and and of line anchors:
    $string =~ /^(?:[^\/]*\/[^\/]*){3}$/;
    

提交回复
热议问题