searching for text in middle of a string

Tagged: 

This topic contains 3 replies, has 4 voices, and was last updated by Profile photo of Olaf Soyk Olaf Soyk 1 month, 1 week ago.

  • Author
    Posts
  • #64258
    Profile photo of Tony Antony
    Tony Antony
    Participant

    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
    Profile photo of Ron
    Ron
    Participant

    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
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    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
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    I couldn't find anything in Google.

    Really? What did you search for?
    Regular Expressions

You must be logged in to reply to this topic.