简体   繁体   中英

Perl regex to match pattern

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM