none
How to code this powershell? RRS feed

  • Question

  • I would like to know on how to set the matching condition in order to retrieve 1 year as return into $match as shown below

    $matches=[regex]::Matches($fileContent,'????(.*?)????')

    Given : skdk kjn kjd<div class="c-time__value">            1        </div>        <div class="c-time__unit">            year        </div> jkdhjfknkjkjd

    Does anyone have any suggestions?
    Thanks in advance for any suggestions

    Thanks in advance for any suggestions

    Tuesday, January 9, 2018 12:16 PM

Answers

  • You could do the following to fill $matches with "1 year" (after using my example):

    $matches = "$($matches[2]) $($matches[5])"

    • Marked as answer by oemMicrosoft Saturday, January 20, 2018 3:01 PM
    Tuesday, January 9, 2018 1:56 PM

All replies

  • Hi,

    Quick & dirty:

    $str = 'skdk kjn kjd<div class="c-time__value">            1        </div>        <div class="c-time__unit">            year        </div> jkdhjfknkjkjd '
    
    $str -match '(c-time__value">\s+)(\d)(.*)(c-time__unit">\s+)(\w+)' | Out-Null
    
    $matches[2] # 1
    $matches[5] # year
    

    Tuesday, January 9, 2018 12:39 PM
  • I would like to retrieve 1 year and assign into $matches, not retrieve each text independently.

    $matches=[regex]::Matches($fileContent,'????(.*?)????')

    Is there any more trick to do that?

    Do you have any suggestions?
    Thank you very much for any suggestions (^v^)


    Thanks in advance for any suggestions

    Tuesday, January 9, 2018 1:30 PM
  • You could do the following to fill $matches with "1 year" (after using my example):

    $matches = "$($matches[2]) $($matches[5])"

    • Marked as answer by oemMicrosoft Saturday, January 20, 2018 3:01 PM
    Tuesday, January 9, 2018 1:56 PM
  • Thank you very much for suggestions (^v^)

    Thanks in advance for any suggestions

    Saturday, January 20, 2018 3:02 PM