Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9145155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:26:37+00:00 2026-06-17T10:26:37+00:00

I need help with this regex. I get a string like below. I want

  • 0

I need help with this regex. I get a string like below. I want something like

ServerName: AdminServer RUNNING
ServerName: ServicesServer1 RUNNING

$rv="xxx ServerName: AdminServer  RUNNING  xxxx ServerName: ServicesServer1  RUNNING xxx"
$rv -replace ".*(ServerName: [A-Za-z0-9]*.*[RUNNING|SHUTDOWN])",'$1'
ServerName: ServicesServer1  RUNNING xxx

With what I have now I only get the last match?

EDIT:

$rv="xxx ServerName: AdminServer  RUNNING  xxxx ServerName: ServicesServer1  RUNNING 
$rv -replace ".*(ServerName: [A-Za-z0-9]*.*RUNNING|SHUTDOWN)",'$1'

gives

ServerName: ServicesServer1  RUNNING xxx

not

ServerName: AdminServer  RUNNING
ServerName: ServicesServer1  RUNNING

EDIT2:
Turns out I have over simplified this. The string looks more like this:

$rv='XXX rtification Authority - G3,OU=(c) 2008 GeoTrust Inc. - For authorized use only,O=GeoTrust Inc.,C=US". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
Successfully Connected to Node Manager.
ServerName: SasTTpcAdminServer

RUNNING

Successfully disconnected from Node Manager.
Connecting to Node Manager ...
Successfully Connected to Node Manager.
ServerName: XXXServicesServer1

RUNNING

Successfully disconnected from Node Manager.'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:26:38+00:00Added an answer on June 17, 2026 at 10:26 am

    While this is not necessarily an ideal approach, it will “work” after fixing some issues:

    1. [RUNNING|SHUTDOWN] is a character calss, not an aliteration. Switch it to (?:RUNNING|SHUTDOWN)

    2. The .*s matches too greedily. Use .*? instead.

    Final:

    $rv -replace ".*?(ServerName: [A-Za-z0-9]*.*?(?:RUNNING|SHUTDOWN))", '$1'
    

    Notice how it doesn’t match the last bit .. however, there is likely a better solution to this (note that this uses the previously discussed fixes and some tweaks of my own):

    $r = [regex]::matches($rv,"(ServerName:.*?\w+.*?(?:RUNNING|SHUTDOWN))")
    $r[0].Value
    # -> ServerName: AdminServer  RUNNING
    

    Then we can map the capture group values into something simpler:

    $r | % { $_.Value }
    # -> 
    # ServerName: AdminServer  RUNNING
    # ServerName: ServicesServer1  RUNNING
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a regex expert to help out on this one. Examples I've found
Not exactly about programming, but I need help with this. I'm running a development
I'm a complete noob to regex and I need help with splitting a string.
Imagine I have a string - something like this: This is some really cool
I need to extract information from an LDAP connection string like this one: ldap://uid=adminuser,dc=example,c=com:secret@ldap.example.com/dc=basePath,dc=example,c=com
I'm not very good for regex and this is why I need your help.
I'm using Sybase 12.5.3, and want/need to do regex pattern matching. The Sybase help
For example I have a string like this: first:second:thirdtest:test:fourth I want to count the
Hi I'm very new to regex and I need some help with writing this
I need help to match a string with a regex. An example of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.