(?:\d{3}-){2}(?:\d{4}) would match a ten digit us-format phone number, though I’d recommend using two literally instead of a repeat for maintainability reasons. Regex needs no assistance being terse and obtuse, humans need time to understand regex patterns, even ones they wrote not long ago. Make that part easier on your collaborators, and treat your past and future selves like remote asynchronous collaborators, always.
Never knew the repeat group bit. Can’t really think of a practical use case for it though…
I use it in Vim. Sometimes you want to rename a variable that’s present multiple times in the same line
True, regex is nothing if not an everything tool!
Why not just match for the variable and use
/g?I assumed that’s what they meant by “group bit”. I guess maybe they were talking about capture groups
(?:\d{3}-){2}(?:\d{4}) would match a ten digit us-format phone number, though I’d recommend using two literally instead of a repeat for maintainability reasons. Regex needs no assistance being terse and obtuse, humans need time to understand regex patterns, even ones they wrote not long ago. Make that part easier on your collaborators, and treat your past and future selves like remote asynchronous collaborators, always.