How to extract a hexadecimal number from the line

OZ 226 Reputation points
2022-02-14T14:17:02.43+00:00

I have a string:

$str='2022-02-14T11:28:35.098Z,"EXCH\FsdY",08D9E74B8841CF38,4,10.66.17.71:25,10.66.17.109:49684,<,MAIL FROM:<user.user@Stuff .com>,'

I want to see only:

08D9E74B8841CF38

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,509 questions
{count} votes

2 answers

Sort by: Most helpful
  1. sok 11 Reputation points
    2022-02-14T14:36:33.877+00:00

    Hello,

    How about this one-liner ?

    $Str.Split(',')[2]
    
    0 comments No comments

  2. OZ 226 Reputation points
    2022-02-14T14:50:10.41+00:00

    Ok, may be this will be enough:
    $str -replace '(.+),([0-9a-f]{16}),(.+)', '$2'

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.