Trying to match a blank column in CSV with regex

Welcome Forums General PowerShell Q&A Trying to match a blank column in CSV with regex

Viewing 4 reply threads
  • Author
    Posts
    • #281627
      Participant
      Topics: 10
      Replies: 11
      Points: 145
      Rank: Participant

      Hello Everyone,

       

      I am trying to match a blank column with regex in CSV and using below code but not returning anything for me. I can find blank column via where object but want to strictly use regex here for matching.

       
      <p class=”p1″>Import-CSV -Path “C:\Servicess.CSV” | Where-Object {$_.Site -Match “\s+”} </p>
       

      Thanks

       

       

    • #281636
      Participant
      Topics: 4
      Replies: 427
      Points: 756
      Helping Hand
      Rank: Major Contributor

      \s+ matches 1 or more whitespace characters but you have an empty cell, not a cell with whitespace characters.  Try using ^$ to match an empty string.

      • This reply was modified 1 month ago by Matt Bloomfield. Reason: Corrected Typo
    • #281642
      Participant
      Topics: 10
      Replies: 11
      Points: 145
      Rank: Participant

      That Worked, Thanks alot.

    • #281677
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,988
      Helping Hand
      Rank: Community Hero

      Another way without regex:

    • #282745
      Participant
      Topics: 10
      Replies: 11
      Points: 145
      Rank: Participant

      Thanks alot.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.