#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    1
    Rep Power
    0

    Get name and address


    Hi all,

    I have text file format as :
    Name: Suzanne D. Scott, M.D.
    Class: 66007
    Birthday: 6/1988
    Regcode: 6221
    Description: lobotango
    Phone: 910-767-9881
    Address: 2995 Crown Piece Drive
    San Antonio, Texas, 240 United States

    ---

    Name: Perter D. Jonh, Msc
    Class: 37007
    Birthday: 12/1977
    Regcode: 6221
    Description: lobotango
    Phone: 172-364-9432
    Address: 6688 King Drive
    Dreame, California, 240 United States


    ---


    Name: Perter D. Jonh, Msc
    Class: 37007
    Birthday: 12/1977
    Regcode: 6221
    Description: lobotango
    Phone: 172-364-9432
    Address: 6688 King Drive
    Dreame, California, 240 United States


    ---

    How can i use Regex to get name and address !
    Address in above file are 2 lines in file.

    Have you any ideas ?

    Thank you very much !
  2. #2
  3. Turn left at the third duck
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Location
    Nelson, NZ
    Posts
    112
    Rep Power
    93
    Hi there,

    Depending on your language, some kind of "match all function" with the following regex will give you the names and addresses.

    Code:
    (?s)Name:([^\r\n]+)[\r\n]+.*?Address:([^\r\n]+[\r\n]+[^\r\n]+)
    The names are in Group 1, the addresses are in Group 2.
    For instance in php you can use a preg_match_all.

    Going to bed now but if you have any question someone else will be able to give you more detail.

IMN logo majestic logo threadwatch logo seochat tools logo