searching for text in middle of a string

Welcome Forums General PowerShell Q&A searching for text in middle of a string

This topic contains 3 replies, has 4 voices, and was last updated by

 
Participant
2 years ago.

  • Author
    Posts
  • #64258

    Participant
    Points: 64
    Rank: Member

    I have a string 1234=4578

    $S = "1234=4578"

    How would I look up only "4578"

    Also, where can I learn more about all these special regex conditions? I only know the basics now.

    I couldn't find anything in Google.

  • #64260
    Ron

    Participant
    Points: 2
    Rank: Member

    Your example is probably too simplistic, you'd want to define what the possible values could/should be to make a proper regex. You can test them here. I like this one more, but its unreachable for me at the moment.

  • #64263

    Moderator
    Points: 24
    Team Member
    Rank: Member

    In this case, you wouldn't need to use a regex. You can split the string at the equal sign and select the 2nd item of the array returned by -split.

    ($S -split '=')[1]

    If you want to use a regex the following simple pattern would work.

    if ($S -match '=(.*)$') {
        $Matches[1]
    }
    

    I hope above helps.

  • #64264

    Participant
    Points: 741
    Helping Hand
    Rank: Major Contributor

    I couldn't find anything in Google.

    Really? What did you search for?
    Regular Expressions

The topic ‘searching for text in middle of a string’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort