首页 > 代码库 > 正则表达式_matches

正则表达式_matches

$name = "abc_2014-06-19.txt"
$name -cmatch ‘^abc_(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})\.txt‘
$matches

$matches.year
$matches.day

 

$id="/cs/blogs/tips/archive/2014/06/12/be-aware-of-side-effects.aspx"
if ($id -cmatch ‘^/cs/blogs/tips/archive/(?<year>\d{4})/(?<month>\d{2})/(?<day>\d{2})/(?<name>.+)\.aspx$‘) {
$year = $matches[‘year‘]
$month = $matches[‘month‘]
$day = $matches[‘day‘]
$name = $matches[‘name‘]
}

$matches