Luis Henrique
Luis Henrique

Reputation: 771

Get specific range with regex within string

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

Upvotes: 1

Views: 25

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626690

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 _.

Upvotes: 1

Related Questions