I’m trying to extract some characters or words from a string using regular expressions..
Examples of my string contains “Size: M” or “Size: Medium” and I want to extract “M” and “Medium”
These can be anywhere within a long string so…
I was trying to use the following but it brings back the colon.
:\s\w
Result : M
But I just want the size and no the colon, I was looking at positive look ahead but not having any luck still excluding the colon.
Use a look-behind so the whole regex matches what you want (no need to use matching groups)
Explanation:
(?<=Size: )means the chars immediately preceding the match must be the literal"Size: ", and importantly is non-capturing\w+means “a word”