C# 正则表达式匹配文件名
我有一些文件名模板,如:C# 正则表达式匹配文件名,c#,regex,parsing,C#,Regex,Parsing,我有一些文件名模板,如: $subject-id$-subject-info.xml $sampleId$-$subjectId$-sample-info.txt $subjectId$-$sampleId$-sample-info.txt $subjectId$-$sampleId$-image-$type$.png $sampleId$-$subjectId$-image-$type$.jpg image-$sampleId$-$subjectId$-$type$.jpg 类型,样本id,
$subject-id$-subject-info.xml
$sampleId$-$subjectId$-sample-info.txt
$subjectId$-$sampleId$-sample-info.txt
$subjectId$-$sampleId$-image-$type$.png
$sampleId$-$subjectId$-image-$type$.jpg
image-$sampleId$-$subjectId$-$type$.jpg
类型
,样本id
,主题id
的顺序未持续设置
我需要选择与此模板匹配的文件
例如:
对于第一个模板加工字符串:
"123A-subject-info.xml" ($subject-id$ is string)
第二:
"2014-04-17-17-42-57-O1CD-sample-info.txt" ($sample-id$ is date time type)
最后:
"image-2014-04-17-17-42-57-01CD-mini.jpg" ($type$ is another string)
我怎么用正则表达式呢?我尝试使用split方法解析这个字符串,但是如果模板被更改,我需要不断重写这个方法。例如,如果文件是php格式的,那么它将是 /^\S[a-zA-Z]+(php)$/ 但是您可以用首选扩展替换php
尝试使用检查正则表达式那么您的第一个模板是什么?能否给出一些您希望与第一个模板“$subject id$-subject info.xml”匹配的示例。在示例中,subject id=0000是否总是4位数字?您使用什么语言?我想在C中使用正则表达式工具#