Bu sorunu regexone.com - http://regexone.com/problem/matching_phone_numbers adresinde buldum. Numarayla eşleşen ve uygun alan kodunu yakalayan tek bir normal ifade yazın. Bu regex'i anlama konusunda yardıma ihtiyacınız var
Exercise 2: Matching Phone Numbers
Task Text Capture Groups
Capture 415-555-1234 415 Success
Capture 650-555-2345 650 Success
Capture (416)555-3456 416 Success
Capture 202 555 4567 202 Success
Capture 4035555678 403 Success
Capture 1 416 555 9292 416 Success
Burada ifadesi
(\d{1}?(\d{2}))
alan kodunu yakalar ama ne anlamamız gerekir benim ilk grup sadece 1 basamak içindir ve isteğe olmasıdır. Ve ikinci grubum sadece 2 basamak tutmalı. 3 rakamı nasıl yakaladı?
Huh? Çünkü 1 + 2 = 3? 2 basamağa ('\ d {2}') veya 3 ('\ d {1} \ d {2}') – h2ooooooo
[* Quantifier: {1}? Tam olarak 1 kez (anlamsız nicelendirici) *] (https://regex101.com/r/xK6sE4/1) –
@ h2ooooooo Son numara 1 416 555 9292 nedir? 1 atlandı ve yakalandı 416 –