searching for text in middle of a string


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

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

    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

    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

    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 '=(.*)$') {

    I hope above helps.

  • #64264
    Profile photo of Olaf Soyk
    Olaf Soyk

    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.