0

If I have a variable string 'testawzoid' , which could have anything before "zoid", how do I remove everything before "zoid" regardless of what comes before "zoid".

It could also be "testaxzoid" or "testaanythingzoid" , I just want to keep "zoid"

I have looked at regex and trim etc with no luck. Can anyone point me int the right direction please? Thanks!

6
  • So you want to keep "zoid" as the content of your variable and remove everything else? ;-) Why don't you re-assign the variable with the string "zoid"? Commented Dec 26, 2019 at 3:28
  • as Olaf pointed out, your description makes no sense. [grin] just replace the string with the string you want. ///// however, i presume you are actually wanting something else, would you please give two or three realistic samples and what result you want from each? Commented Dec 26, 2019 at 3:31
  • 2
    You can do $stringVar -replace '.*(?=zoid)' Commented Dec 26, 2019 at 4:09
  • Thank you @AdminOfThings, that is EXACTLY what I was looking for. Commented Dec 26, 2019 at 4:50
  • @Olaf when I was speaking about a variable string, I meant a string which is not always the same. The word 'variable' , in this case is not computer language but rather they way the ancient Romans meant it - late Middle English: via Old French from Latin variabilis, from variare Commented Dec 26, 2019 at 4:54

1 Answer 1

1

As @adminofthings stated in above comment you can use

"testaxzoid" -replace '.*(?=zoid)' 

Here is a tio link if you want to test it. The example uses a regex with a positive look ahead, which is explained here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.