using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
public class Program
{
// Static compiled Regex instance compatible with standard Mono C#.
// Matches standalone floating-point numbers containing an explicit decimal point.
private static readonly Regex FloatRegex = new Regex(@"\b\d+\.\d+\b", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
/// <summary>
/// Extracts all double-precision floating-point numbers containing a decimal point from an input string.
/// </summary>
/// <param name="input">Source text containing mixed words and numerical values.</param>
/// <returns>A list of successfully parsed double values.</returns>
public static List<double> ExtractFloats(string input)
{
List<double> results = new List<double>();
if (string.IsNullOrEmpty(input)) {
return results;
}
// Scan the string for regex matches
MatchCollection matches = FloatRegex.Matches(input);
foreach (Match match in matches) {
double parsedValue;
// Use CultureInfo.InvariantCulture to guarantee '.' is treated as decimal separator across all locales
if (double.TryParse(match.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out parsedValue))
{
results.Add(parsedValue);
}
}
return results;
}
public static void Main(string[] args)
{
string s = "c/c++ c# go 893725.1045 java python 3.14 php 0.0076 javascript";
List<double> extractedNumbers = ExtractFloats(s);
Console.WriteLine("Extracted floating-point numbers:");
foreach (double number in extractedNumbers) {
// Print using InvariantCulture to ensure dot formatting
Console.WriteLine(number.ToString(CultureInfo.InvariantCulture));
}
}
}
/*
run:
Extracted floating-point numbers:
893725.1045
3.14
0.0076
*/