I have written a simple script to match book titles that contain a 4-digit year field enclosed in parenthesis, and additionally, that the 4-digit year begins with ‘1’ or ‘2’:
$test = @(Book1 (1995), Book2 (2001), Book3 (2004) ...) Foreach ($t in $test) { $t -match '^.+\((1|2)\d{3}\)' }
The above seems to work fine, but I need to get an integer value that tells me starting where in the string the match occurred – so I can extract it. Can PS/Regex return such a value? Would be grateful for any tips or guidance. Thanks in advance.