Match specific length x or y

后端 未结 3 1387
Happy的楠姐
Happy的楠姐 2020-12-08 04:59

I\'d like a regex that is either X or Y characters long. For example, match a string that is either 8 or 11 characters long. I have currently implemented this like

3条回答
  •  离开以前
    2020-12-08 05:29

    With Perl, you could do:

    my $re = qr/here_is_your_regex_part/;
    my $full_regex = qr/$re{8}(?:$re{3})?$/
    

提交回复
热议问题