I'm practicing PowerShell on Codewars. I'm currently struggling with this rather easy exercise.
My problem is that my match is not matching correctly or I haven't understood what kind of string the Input is. I'm trying find the data set to a given number. The input is a string, representing a phonebook. The information in each set is in a random order.
So I already tried to first split the input after every new line (-split "\n"
). Didn't work, so I tried it with match. (e.g. -match ".*48-421-674-8974.*\n"
).
Now what I would expect in Matches
, is all information to that number until the next '\n'. But instead I'm getting the data set I wanted PLUS the next line. I've already tried \\n
, \\\\n
, single/double quotes. But I can't find any solution by myself.
So currently my input is this:
"<Sophia Loren> +1-421-674-8974 Bern TP-46017\n <Peter O'Brien> High
Street +1-908-512-2222; CC-47209\n"*
"<Anastasia> +48-421-674-8974 Via Quirinal Roma\n <P Salinger>
Main Street, +1-098-512-2222, Denver\n"*
"<C Powel> *+19-421-674-8974 Chateau des Fosses Strasbourg F-68000\n
<Bernard >Deltheil +1-498-512-2222; Mount Av. Eldorado\n"
And my regex ".*48-421-674-8974.*\\n"
I'd expect this result:
<Anastasia> +48-421-674-8974 Via Quirinal Roma\n
but I'm getting:
"<Anastasia> +48-421-674-8974 Via Quirinal Roma\n <P Salinger> Main Street, +1-098-512-2222, Denver\n"
I've also tried matching or spliting again after this result, but that did'nt work either.