2013-02-05 2 views
1

VCard 4.0 파일을 읽고 싶습니다.VCard 4.0 전화 Regex?

이 샘플을 사용합니다.

그러나이 솔루션을이 파일에 사용할 때.

RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace; 
    regex = new Regex(@"(\n(?<strElement>(TEL)) (;*(?<strAttr>(HOME|WORK)))* (;(?<strType>(VOICE|CELL|PAGER|MSG|FAX)))* (;(?<strPref>(PREF)))* (;[^:]*)* (:(?<strValue>[^\n\r]*)))", options); 


mc = regex.Matches(s); 
      if (mc.Count > 0) 
      { 
       Phones = new Phone[mc.Count]; 
       for (int i = 0; i < mc.Count; i++) 
       { 
        m = mc[i]; 
        Phones[i].number = m.Groups["strValue"].Value; 
        ss = m.Groups["strAttr"].Value; 
        if (ss == "HOME") 
         Phones[i].homeWorkType = HomeWorkType.home; 
        else if (ss == "WORK") 
         Phones[i].homeWorkType = HomeWorkType.work; 

        if (m.Groups["strPref"].Value == "PREF") 
         Phones[i].pref = true; 

        ss = m.Groups["strType"].Value; 
        if (ss == "VOICE") 
         Phones[i].phoneType = PhoneType.VOICE; 
        else if (ss == "CELL") 
         Phones[i].phoneType = PhoneType.CELL; 
        else if (ss == "PAGER") 
         Phones[i].phoneType = PhoneType.PAGER; 
        else if (ss == "MSG") 
         Phones[i].phoneType = PhoneType.MSG; 
        else if (ss == "FAX") 
         Phones[i].phoneType = PhoneType.FAX; 


       } 
      } 

을하지만 빈에서 strAttr의 값 strType : 예를 들어, 내가 전화 번호를이 정규식을 사용 -

BEGIN:VCARD 
VERSION:4.0 
N:Gump;Forrest;;; 
FN: Forrest Gump 
ORG:Bubba Gump Shrimp Co. 
TITLE:Shrimp Man 
PHOTO:http://www.example.com/dir_photos/my_photo.gif 
TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212 
TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212 
ADR;TYPE=work;LABEL="42 Plantation St.\nBaytown, LA 30314\nUnited States of America" 
:;;42 Plantation St.;Baytown;LA;30314;United States of America 
EMAIL:[email protected] 
REV:20080424T195243Z 
END:VCARD 

는 전화 매개 변수를 찾을 수 없습니다.

어떻게 정규식을 설정 하시겠습니까? 대신 vCard를 클래스 라이브러리를 시도 정규 표현식의

답변