从特定字符串模式中提取部分

Mur*_*hy 2 c#

我怎样才能从下面的字符串中得到时差,我想得到它(-3.30)

[UTC - 3:30] Newfoundland Standard Time
Run Code Online (Sandbox Code Playgroud)

以及如何从下面的字符串中获取null

[UTC] Western European Time, Greenwich Mean Time
Run Code Online (Sandbox Code Playgroud)

我想在下面的字符串中得到+3.30

[UTC + 3:30] Iran Standard Time
Run Code Online (Sandbox Code Playgroud)

Bar*_*osz 5

正则表达式:

\[UTC([\s-+0-9:]*)\]
Run Code Online (Sandbox Code Playgroud)

第一组是- 3:30.(带空格)

var regex = new Regex(@"\[UTC([\s-+0-9:]*)\]");
var match = regex.Match(inputString);

string timediff;
if(match.Groups.Count > 0)
    timediff = match.Groups[1].Value.Replace(" ", String.Empty); // if you don't want those spaces
else
    // no timediff here
Run Code Online (Sandbox Code Playgroud)