I have some template for file names like:
$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
order of type
, sample-id
, subject-id
not constantly set.
I need to select files which matching this templates.
for example:
for first template maching string:
"123A-subject-info.xml" ($subject-id$ is string)
for second:
"2014-04-17-17-42-57-O1CD-sample-info.txt" ($sample-id$ is date time type)
for last:
"image-2014-04-17-17-42-57-01CD-mini.jpg" ($type$ is another string)
How can i do it with regex ? I try to parsing this strings using split method, but i need to rewrite this method constantly if the template was changed.
For example if the file is in php then it would be /^\S[a-zA-Z]+.(php)$/ But you can replace php with your preferred extension.
try using http://regex101.com/ to check your regular expression
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With