Here is a string, which I call data
:
(1) Turkey - Italy @ Stadio Olimpico, Rome
(2) Wales - Switzerland @ Olympic Stadium, Baku
I can process it as follows:
StringReplace[
"(" ~~ id__ ~~ ")" ~~ Whitespace ~~ Shortest[team1__] ~~
Whitespace ~~ "-" ~~ Whitespace ~~ Shortest[team2__] ~~
Whitespace ~~ "@ " ~~ venue__ :> <|"id" -> ToExpression[id],
"team1" -> team1, "team2" -> team2, "venue" -> venue|>] /@
ImportString[data, "Lines"]
But the result of each is a StringExpression
:
(* {StringExpression[<|"id" -> 1, "team1" -> "Turkey",
"team2" -> "Italy", "venue" -> "Stadio Olimpico, Rome"|>],
StringExpression[<|"id" -> 2, "team1" -> "Wales",
"team2" -> "Switzerland", "venue" -> "Olympic Stadium, Baku"|>]} *)
I can use Identity@@@
to remove StringExpression
, but the fact that StringReplace
gives me such a weird output makes me think that it must not be right tool for the job. Is there a better way?