简体   繁体   English

Java Regex查找以SDPCDR_开头的字符串

[英]Java Regex to find a string which starts with SDPCDR_

what is the regular expression which i should use to match a string which starts with SDPCDR and contains date in the format 20120826 and ends with .asn ? 我应该使用什么正则表达式来匹配以SDPCDR并包含日期格式为20120826并以.asn结尾的.asn

an example string is SDPCDR_delsdp3a_6091_20120826-042451.asn 示例字符串是SDPCDR_delsdp3a_6091_20120826-042451.asn

这将工作:

^SDPCDR\w+(\d{8})-\w+.asn$
"^SDPCDR.*\\d{8}.*\\.asn$"

Pretty generous on the date part, but the string is probably specific enough already to avoid false matches. 日期部分相当宽泛,但是字符串可能已经足够具体,可以避免错误匹配。 If you're looking for a substring rather than trying to match the entire string, instead use 如果您要查找子字符串而不是尝试匹配整个字符串,请使用

"SDPCDR.*?\\d{8}.*?\\.asn"
SDPCR_[a-z_]*[0-9]{8,8}-[a-z_]*\\\\.asn

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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