i have tried all manner of combination, but my regex is always greedy.
I want to capture only the number from
"size": 987987,
something like this? "size": (.+?),
i have tried all manner of combination, but my regex is always greedy.
I want to capture only the number from
"size": 987987,
something like this? "size": (.+?),
The regex you provided will indeed capture only the number (in this case); what exactly to you mean by “capture” here? (or put another way, what is it you’re trying to do exactly?)
if you are using ST’s find panel, you could use a lookbehind or \K
to only select the number, like
(?<="size":\s*)\d+
or "size":\s*\K\d+
capture groups don’t affect anything in ST in Find mode - they are only useful when making replacements
@OdatNurd Sorry for not stating the most important thing. I want to use the Find function of ST3 to highlight certain text.
@kingkeith this works: "size":\s*\K\d+
But I don’t understand why the non-greedy regex I suggested does not. Is there something special about regex syntax in Find?
There isn’t really anything special about it, but it doesn’t individually highlight capture groups, just the total match (aka match 0).
The \K
syntax resets the match, so it effectively deletes everything from the match before the digits.