Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That's a terrible regular expression! <code>.*</code> and <code>.*?</code> mean to match as many (greedy) or as few (lazy) of anything. These should only be used as a last resort. Improper use will result in <a href="http://www.regular-expressions.info/catastrophic.html" rel="nofollow noreferrer">catastrophic backtracking</a> when the regex cannot match the input text. All you need to understand about this regular expression that you don't want to write regexes like this.</p> <p>Let me show how I would approach the problem. Apparently the <a href="http://developer.apple.com/internet/appleapplications/icalendarfiles.html" rel="nofollow noreferrer">iCalendar File Format</a> is line-based. Each line has a property and a value separated by a colon. The property can have parameters that are separated from it by a semicolon. This implies that a property cannot contain line breaks, semicolons or colons, that the optional parameters cannot contain line breaks or colons, and that the value cannot contain line breaks. This knowledge allows us to write an efficient regular expression that uses <a href="http://www.regular-expressions.info/charclass.html" rel="nofollow noreferrer">negated character classes</a>:</p> <pre><code>([^\r\n;:]+)(;[^\r\n:]+)?:(.+) </code></pre> <p>Or in ActionScript:</p> <pre><code>var matches:Array = data.match(/([^\r\n;:]+)(;[^\r\n:]+)?:(.+)/); p.name = matches[1]; p.value = matches[3]; p.paramString = matches[2]; </code></pre> <p>As explained by RegexBuddy:</p> <pre><code>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) «+» </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload