2010-03-19 5 views
0

라이브러리를 사용하여 iCalendar 파일을 구문 분석하지만 정규식 분할 속성을 이해하지 못합니다.ActionScript에서 iCalendar 파일을 정규 표현식으로 구문 분석

BEGIN:VEVENT 
DTSTART;VALUE=DATE:20080402 
RRULE:FREQ=YEARLY;WKST=MO 

라이브러리는 이해하고 싶은이 정규식을 사용합니다 :

var matches:Array = data.match(/(.+?)(;(.*?)=(.*?)((,(.*?)=(.*?))*?))?:(.*)$/); 
p.name = matches[1]; 
p.value = matches[9];     
p.paramString = matches[2]; 

감사
을 iCalendar 속성은 3 가지 다른 스타일을 가지고있다.

+2

:로 RegexBuddy에 의해 설명

var matches:Array = data.match(/([^\r\n;:]+)(;[^\r\n:]+)?:(.+)/); p.name = matches[1]; p.value = matches[3]; p.paramString = matches[2]; 

를이 지식은 우리가 negated character classes를 사용하는 효율적인 정규 표현식을 쓸 수 있습니다 아무도 그것을 설명하고 싶어하지 않는다 : P. 꽤 기본적인 것들입니다. "그룹 포착"과 "욕심이 많지 않음"을 검색하면 알아낼 것입니다. – Kobi

답변

5

끔찍한 정규 표현식입니다. .*.*?은 많은 것을 (탐욕스러운) 또는 몇 가지 (게으른) 것과 일치시키는 것을 의미합니다. 이것들은 최후의 수단으로 사용해야합니다. 부적절한 사용은 정규식이 입력 텍스트와 일치하지 않을 때 catastrophic backtracking이됩니다. 이 정규 표현식에 대해 이해해야 할 필요가있는 모든 정규식을 이와 같이 작성하고 싶지는 않습니다.

어떻게 문제에 접근 할 수 있는지 보여 드리겠습니다. 분명히 iCalendar File Format은 회선 기반입니다. 각 행에는 속성과 콜론으로 구분 된 값이 있습니다. 이 속성은 세미콜론으로 구분 된 매개 변수를 가질 수 있습니다. 이는 속성에 줄 바꿈, 세미콜론 또는 콜론을 포함 할 수 없으며 선택적 매개 변수에 줄 바꿈이나 콜론을 포함 할 수없고 줄 바꿈을 포함 할 수 없음을 의미합니다.

([^\r\n;:]+)(;[^\r\n:]+)?:(.+) 

또는 ActionScript의 : 정규식 같아요 그렇게 반발하는지

Match the regular expression below and capture its match into backreference number 1 «([^\r\n;:]+)» 
    Match a single character NOT present in the list below «[^\r\n;:]+» 
     Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» 
     A carriage return character «\r» 
     A line feed character «\n» 
     One of the characters “;:” «;:» 
Match the regular expression below and capture its match into backreference number 2 «(;[^\r\n:]+)?» 
    Between zero and one times, as many times as possible, giving back as needed (greedy) «?» 
    Match the character “;” literally «;» 
    Match a single character NOT present in the list below «[^\r\n:]+» 
     Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» 
     A carriage return character «\r» 
     A line feed character «\n» 
     The character “:” «:» 
Match the character “:” literally «:» 
Match the regular expression below and capture its match into backreference number 3 «(.+)» 
    Match any single character that is not a line break character «.+» 
     Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» 
+0

+1 좋은 설명! –

관련 문제