This is my input file which is random, can be any number not just 9999 and any letters:
The below format will always come after a - (dash).
- 9999 99AKDSLY9ZWSRK99999 9999 99BGRPOE99FTRQ99999
Expected output:
AKDSLY9ZSRK BGRPOE99TRQ
So I need to remove the first part of each line, always numbers:
9999 99 9999 99
Then remove the not-required characters:
99AKDSLY9ZW → in this case is the W but could be any letter
99BGRPOE99F → in this case is the F but could be any letter
And finally remove the last 5 digits, always numbers:
99999 99999
What I´m trying to use, regex (first time using it):
$result = [regex]::Matches($InputFile, '(^\d{4}\s\d{2}[A-Z0-9]\d{5}$)') -replace '\d{4}\s\d{2}', '')
$result
It's not giving me an error message but it's not showing me the characters I'm expecting to see at $result.
I was expecting to see something in $result to then start the formatting, deleting the characters I don't need.
What could be missing here, please?
^[\d ]*(.+?)[\d ]*$replace$1, thenThen remove the not-required charactersin a separate regex operation. Set multi-line mode for both regex operations.start of string, four digits, space, two digits, a single letter or number, five digits, end of string- because of the single letter or number, it will never match anything. (and even if you change it to match, the match would be the entire line, which makes it useless)'9999 99BGRPOE99FTRQ99999' -replace '^\d{4} \d{2}|\d{5}$' -replace '.(?=...$)'to replace the start or the end numbers, then replace the fourth-from-last-character (my best guess as to why you are chosing the W and F...)