I'm trying to capture a specific sequence of letters and numbers in a CSV field. The field can contain the following:
"Some random text WMM540" < cell text
EDIT: Here's the raw csv:
Employee ID,First Name,Surname,Base Store Code,Job Title
555555,Mark,Testing-Process,Mo Newcastle Under Lyme WMM222,Merchandiser
555556,Carly,O'Test,AS Congleton ASD1111,Supervisor
I need to capture the WMMXXX (where X is the number) in a variable, but there can be more codes. The possible codes I need to get are:
WMMXXX
MORXXX
ASDXXXX (4 digits instead of 3)
WILXXX
PLDXXX
SUPXXX
.. and a few more.
I'm aware you can split and isolate text using regex, but I don't have enough experience with it.
Ultimately I need a variable that looks like: $v = 'WMMXXX'
Please could you help?
Many thanks
$v = if ($cellValue -match '((?:WMM|MOR|WIL|PLD|SUP)\d{3}|ASD\d{4})') { $matches[1] }should work, but we really need more details...$v = $cellValue -replace '^.* '. This simply strips everything up to and including the last space from the input string.