开发者

Perl regex to match pattern

开发者 https://www.devze.com 2023-02-15 19:37 出处:网络
I need to match a string something like $filecontents = test-app-ref-Man_pub_aut_art_1234; My regex is something like this but it doesn\'t work: Can someone help me with the regex 开发者_如何转开发

I need to match a string something like

$filecontents = test-app-ref-Man_pub_aut_art_1234;

My regex is something like this but it doesn't work: Can someone help me with the regex 开发者_如何转开发what I am doing wrong here. Please note that I am reading the complete file as a string and this is one of the strings.

while($filecontents =~ m/(test)(-|_)(.*)(_\d{4,})$/isgm){
    print " String10 : '$1$2$3$4'\n";
}


looks like you're expecting the string to end with 4 digits, but your string actually ends with 4 digits, then a semi-colon. add a semi-colon before the $


Try this one, worked for me in Excel

(-|_)?.*_\d{4}

Result for the given string:

test-app-ref-Man_pub_aut_art_1234

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号