Example #1
0
		static public int? SecondCountFromBracketTimerText(
			this string timerText,
			bool allowLeadingText = false,
			bool allowTrailingText = false)
		{
			const string groupMinuteId = "minute";
			const string groupSecondId = "second";

			var pattern = @"((?<" + groupMinuteId + @">\d+)m\s*|)(?<" + groupSecondId + @">\d{1,2})\s*s";

			if (!allowLeadingText)
				pattern = @"^\s*" + pattern;

			if (!allowTrailingText)
				pattern += @"\s*$";

			var match = timerText?.RegexMatchIfSuccess(pattern, RegexOptions.IgnoreCase);

			if (null == match)
				return null;

			var minuteCount = match.Groups[groupMinuteId]?.Value.TryParseInt() ?? 0;
			var inMinuteSecondCount = match.Groups[groupSecondId]?.Value.TryParseInt();

			return minuteCount * 60 + inMinuteSecondCount;
		}
Example #2
0
		static public Int64? NumberParseDecimalMilliBetween(
			this string stringContainingNumber,
			string prefixPattern = null,
			string suffixPattern = null,
			RegexOptions regexOptions = RegexOptions.None)
		{
			var numberGroupName = "TheNumberGroup";

			var pattern =
				prefixPattern +
				"(?<" + numberGroupName + ">" +
				DefaultNumberFormatRegexPatternAllowLeadingAndTrailingChars +
				")" +
				suffixPattern;

			var match = stringContainingNumber?.RegexMatchIfSuccess(pattern);

			return match?.Groups[numberGroupName]?.Value?.NumberParseDecimalMilli();
		}