1

Get specific range with regex within string

REGEX:

-(.*).......:

DATA

SRV-srvdata-q_SRV_20:DAT
SRV-srvdata-p:DAT

OUTPUT

hoinvap01-q
hoha

GOAL

srvdata-q
srvdata-p
2
  • 1
    Try -([^:_]+) Commented Oct 8, 2019 at 12:39
  • Perfect, thanks !!!!! Commented Oct 8, 2019 at 12:41

1 Answer 1

1

You want to match any 1+ chars from the first hyphen to the first _ or :.

You may use

-([^:_]+)

See the regex demo

The [^:_]+ will match any 1+ chars other than : and _.

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.