Regular expression for a JIRA identifier

前端 未结 3 1452
孤街浪徒
孤街浪徒 2021-01-03 22:19

I\'m trying to extract a JIRA identifier from a line of text.

JIRA identifiers are of the form [A-Z]+-[0-9] - I have the following pattern:

foreach m         


        
3条回答
  •  盖世英雄少女心
    2021-01-03 22:44

    You can make sure that character before your pattern is either a whitespace, or the beginning of the string using alternation. Similarly make sure, it is followed by either whitespace or end of the string.

    You can use this regex:

    my ( $id ) = ( $line =~ /(?:\s|^)([A-Z]+-[0-9]+)(?=\s|$)/ );
    

提交回复
热议问题