Reputation: 589
I am getting below string as output
RX Power: -3.4 dBm (460.9uW)
I tried below code but I am getting output like
: -3.4 d
I want output
-3.4
$pattern = '(?s)\:.*? d+'
[regex]::Matches($RXTX_Data[0], $pattern).Value
Please let me know what is missing here
Upvotes: 0
Views: 45
Reputation: 84
(Assumed you are looking to get the dBm value)
You can just select the text between the keywords using.
RX Power:(.*)dBm
This will give you an answer that includes the spaces (leading and trailing) - but you can easily remove those.
$pattern = 'RX Power:(.*)dBm'
[regex]::Matches($RXTX_Data[0], $pattern).Value.Replace(" ","")
I'm sure you could remove it in regex as well but I could only get the leading spaces removed using:
RX Power:\s*(.*)dBm
Upvotes: 1
Reputation: 185
Try \s(-?\d+.?\d+)\s
for your pattern.
It worked for me on https://regex101.com. If you haven't heard of it, it's a good place to practice regex.
Upvotes: 1