Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
regex解析ActionScript中的iCalendar文件_Regex_Actionscript 3_Parsing_Icalendar - Fatal编程技术网

regex解析ActionScript中的iCalendar文件

regex解析ActionScript中的iCalendar文件,regex,actionscript-3,parsing,icalendar,Regex,Actionscript 3,Parsing,Icalendar,我使用库解析iCalendar文件,但我不理解regex to split属性。 iCalendar属性有3种不同的样式: BEGIN:VEVENT DTSTART;VALUE=DATE:20080402 RRULE:FREQ=YEARLY;WKST=MO 库使用我想了解的正则表达式: var matches:Array = data.match(/(.+?)(;(.*?)=(.*?)((,(.*?)=(.*?))*?))?:(.*)$/); p.name = matches[1]; p.va

我使用库解析iCalendar文件,但我不理解regex to split属性。
iCalendar属性有3种不同的样式:

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];

谢谢。

这是一个糟糕的正则表达式
*
*?
意味着匹配尽可能多(贪婪)或尽可能少(懒惰)的任何东西。这些措施只能作为最后手段。如果使用不当,将导致正则表达式与输入文本不匹配。你需要了解的就是这个正则表达式,你不想这样写正则表达式

让我展示一下我将如何处理这个问题。很明显,这是基于线路的。每行都有一个属性和一个由冒号分隔的值。属性可以包含用分号分隔的参数。这意味着属性不能包含换行符、分号或冒号,可选参数不能包含换行符或冒号,值不能包含换行符。这些知识使我们能够编写一个高效的正则表达式,它使用:

或者在ActionScript中:

var matches:Array = data.match(/([^\r\n;:]+)(;[^\r\n:]+)?:(.+)/);  
p.name = matches[1];
p.value = matches[3];
p.paramString = matches[2];
正如RegexBuddy所解释的:

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) «+»

这是一个糟糕的正则表达式
*
*?
意味着匹配尽可能多(贪婪)或尽可能少(懒惰)的任何东西。这些措施只能作为最后手段。如果使用不当,将导致正则表达式与输入文本不匹配。你需要了解的就是这个正则表达式,你不想这样写正则表达式

让我展示一下我将如何处理这个问题。很明显,这是基于线路的。每行都有一个属性和一个由冒号分隔的值。属性可以包含用分号分隔的参数。这意味着属性不能包含换行符、分号或冒号,可选参数不能包含换行符或冒号,值不能包含换行符。这些知识使我们能够编写一个高效的正则表达式,它使用:

或者在ActionScript中:

var matches:Array = data.match(/([^\r\n;:]+)(;[^\r\n:]+)?:(.+)/);  
p.name = matches[1];
p.value = matches[3];
p.paramString = matches[2];
正如RegexBuddy所解释的:

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) «+»

那个正则表达式太恶心了,我想没人想解释它:P。不过,这是非常基本的东西——搜索“捕获组”和“非贪婪”,你会发现。正则表达式太令人讨厌了,我想没人想解释它:P。不过,这是非常基本的东西——搜索“捕获群”和“非贪婪”,你会找到答案的。