Imports System
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Text.RegularExpressions
Module Program
' Compiled Regex pattern matching standalone numbers with explicit decimal points.
' \b defines word boundaries; \d+ matches whole digits before and after the dot.
Private ReadOnly FloatPattern As New Regex("\b\d+\.\d+\b", RegexOptions.Compiled)
''' <summary>
''' Extracts all floating-point numbers containing explicit decimal points from an input string.
''' </summary>
''' <param name="input">The source string containing text and numerical tokens.</param>
''' <returns>A list of parsed double precision floating-point numbers.</returns>
Public Function ExtractFloats(input As String) As List(Of Double)
Dim results As New List(Of Double)()
If String.IsNullOrWhiteSpace(input) Then
Return results
End If
' Find all regex matches matching the floating-point pattern
Dim matches As MatchCollection = FloatPattern.Matches(input)
For Each match As Match In matches
Dim parsedValue As Double
' CultureInfo.InvariantCulture ensures the decimal point (.) is parsed correctly
' regardless of the local system's regional settings (e.g., regions using commas).
If Double.TryParse(match.Value, NumberStyles.Float, CultureInfo.InvariantCulture, parsedValue) Then
results.Add(parsedValue)
End If
Next
Return results
End Function
Sub Main()
' Example input string
Dim s As String = "c/c++ c# go 893725.1045 java python 3.14 php 0.0076 javascript"
' Call extraction function
Dim floatNumbers As List(Of Double) = ExtractFloats(s)
' Display extracted numbers using InvariantCulture to print standard dots
Console.WriteLine("Extracted floating-point numbers:")
For Each number As Double In floatNumbers
Console.WriteLine(number.ToString(CultureInfo.InvariantCulture))
Next
End Sub
End Module
' run:
'
' Extracted floating-point numbers:
' 893725.1045
' 3.14
' 0.0076
'