grep with regex for phone number

后端 未结 11 2137
盖世英雄少女心
盖世英雄少女心 2020-12-04 22:39

I would like to get the phone numbers from a file. I know the numbers have different forms, I can handle for a single one, but don\'t know how to get a uniform regex. For ex

11条回答
  •  借酒劲吻你
    2020-12-04 23:04

    Try this one:

    ^(\d{10}|((([0-9]{3})\s){2})[0-9]{4}|((([0-9]{3})\-){2})[0-9]{4}|([(][0-9]{3}[)])[0-9]{3}[-][0-9]{4})$

    This is only applicable for the formate you mention above like:

    1. xxxxxxxxxx
    2. xxx xxx xxxx
    3. xxx-xxx-xxxx
    4. (xxx)xxx-xxxx

提交回复
热议问题