Reputation: 531
I have one string for ex. "Drive C: Disk Usage".
Everything after the ":" is a text I want to extract with regex.
(here, its "Disk Usage")
I am parsing it with this regex:
:[^:].*
but it considers ":" as well which i don't want .
How can I change my regular expression so that it will match any text after ":"
Please help.
Upvotes: 0
Views: 1066
Reputation: 174706
Use a positive lookbehind,
(?<=:).*
It matches all the characters which are just after to :
.
Explanation:
(?<=)
Positive lookbehind..*
Matches any character(except a newline character) zero or more times.OR
:\K[^:].*
Explanation:
:
A literal :
\K
Used to discard previously matched characters.(ie; :
).*
Any character(except a newline character) zero or more times.Upvotes: 2
Reputation: 791
Some options
Positive lookbehind
(?<=:).*
Negative ( this should be faster )
[^:]*$
Matches everything after a : , it's after because we are using the end delimiter.
Upvotes: -1