Reputation: 31
I'm learning regex on regexone.com. In exercise 2: Matching Phone Numbers, The same patterns work differently between regexone.com and VSCode's find/replace feature.
The exercise shows these test cases:
415-555-1234
650-555-2345
(416)555-3456
202 555 4567
4035555678
1 416 555 9292
The goal is to capture only the area codes (the first three contiguous numbers) for each line which are :
415
650
416
202
403
416
On regexone.com, the pattern (\d{3})
successfully captures these area codes in all cases.
However, in VSCode's find/replace, this same pattern doesn't work as expected - particularly with the (416) case and the "1 416" case.
I've tried variations like:
(?:1 )?(\d{3})
^.{0,2}(\d{3})
\(?(\d{3})
But none perfectly match regexone.com's behaviour. What's the correct pattern for VSCode that will capture area codes in all these formats? And why does VSCode handle this differently?
Upvotes: 0
Views: 52