次のコード例では、正規表現で文字列のリストをフィルタリングしています。その文字列に一致するエントリは 1 つしかないことがわかっています。次に、同じ一致文字列を使用して、残りの 1 つの値からグループ化された 2 つの値を取得します。
let input = ["aaaa bbbb";"aaabbbb";"cccc$$$$";"dddddda";" "]
let ValuesOfAB (input: string list) =
let matchString = "(?<a>\w+)\s(?<b>\w+)"
let value = input |> List.filter (fun line -> Regex.Matches(line, matchString).Count <> 0)
|> List.head
(Regex.Matches(value, matchString).[0].Groups.["a"].Value, Regex.Matches(value, matchString).[0].Groups.["b"].Value)
let a = ValuesOfAB input
戻りたい値を取得するために、同じ文字列で Regex.Matches をもう一度使用する必要がないより良い方法はありますか?