Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fetch value between 2 characters from a string

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

-3.4
$pattern = '(?s)\:.*? d+'
[regex]::Matches($RXTX_Data[0], $pattern).Value

Please let me know what is missing here

>Solution :

Try \s(-?\d+.?\d+)\s for your pattern.


  • \s for whitespace character on either side of number
  • -? for checking if ‘-‘ is in number group
  • .? for checking if ‘.’ is in number group
  • \d+ for matching 1 or more numbers in number group
  • () for specifying the group you wish to capture i.e. the number group

It worked for me on https://regex101.com. If you haven’t heard of it, it’s a good place to practice regex.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading