0

I have a line of text in a string that I need to replace part of it.

$OrgString = "BLUE ORIGIN             CONTACT:  MB"
$OrgString -replace 'CONTACT:'

I need to remove CONTACT: MB Keep in mind that the only thing that will be consistent in string will be CONTACT:. Everything else in the string will vary. Is there a way to do a -replace 'CONTACT:' plus a "number" of characters?

1
  • 1
    more examples of your expected output. do you want all the trailing spaces/etc. 'BLUE ORIGIN ' is different than 'BLUE ORIGIN' Commented Dec 11, 2018 at 21:28

1 Answer 1

1

As the -replace operator is regular expressions based, you should learn about RegEx

To match up to line end use .*$

$OrgString = "BLUE ORIGIN             CONTACT:  MB"
$OrgString -replace 'CONTACT:.*$','#'

BLUE ORIGIN             #

If something else follows that should NOT be deleted,

$OrgString = "BLUE ORIGIN             CONTACT:  MB  SOMETHING:  ELSE"
$OrgString -replace 'CONTACT:\s+\S+\s+'

BLUE ORIGIN             SOMETHING:  ELSE
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.