Capture Characters after special Char with Regex

1593 views regex
3

I have strings that are built like this

"Colour: Black
Size: L"

"Colour: Black
Size: XS"

All i want to capture are the characters after Size: but with no whitespace, I have come up with the following

(?<=\Size:)[^\]]+

answered question

So what's your question? Is it not working the way you expect? What results are you getting?

Im getting space after Size: so im looking to get rid of the white space also.

2 Answers

10

You can use this regex and capture group 1's content,

^Size:\s+(.*?)$

Explanation:

  • ^ --> start of string
  • Size:\s+ --> This matches Size: literally followed by one or more whitespace characters
  • (.*?) --> Captures the string you are interested in
  • $ Matches end of string

Demo, https://regex101.com/r/hxi7dJ/2

posted this
0

Try Regex: (?<=Size: ).*?(?=")

Demo

posted this

Have an answer?

JD

Please login first before posting an answer.