Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In your code you have</p> <pre><code>var regexp = new RegExp("/DTSTART:(.*?)\s/", "g"); </code></pre> <p>but the regular expression delimiter <code>/</code> is not required when passing a string to the <code>RegExp</code> constructor - it will be interpreted as a character to be matched. Also, as its a string any special RegExp characters need to be double escaped, so <code>\s</code> should be <code>\\s</code>. </p> <p>Here is one way of getting the values for each specified tag: </p> <pre><code>var match, matches = [], tags = 'DTSTART|DTEND|DTSTAMP|UID|CREATED|DESCRIPTION|' + 'LAST-MODIFIED|LOCATION|STATUS|SUMMARY|TRANSP', regexp = new RegExp( '(?:' + tags + '):([\\s\\S]*?)(?=\\s+(?:' + tags + '|SEQUENCE|END):)', 'g' ); while ( match = regexp.exec( file_content ) ) { matches.push( match[1] ); } </code></pre> <p>If you want to retrieve each tag:value pair, change <code>match[1]</code> to <code>match[0]</code>. </p> <p>The above assumes that there is at least one space or newline character before each tag.<br> It also assumes that a space followed by a tag name followed by a <code>:</code> does not appear in any tag's value. </p> <p><code>[\\s\\S]</code> is used instead of <code>.</code> so that newline characters can be included in a tag's value.</p> <p>The above does not capture the value of the <code>SEQUENCE</code> tag as it was not specified in the list.<br> If you want to capture it, just add it to <code>tags</code> and remove it from <code>regexp</code> so <code>'|SEQUENCE|END):)'</code> becomes <code>'|END):)'</code>.</p> <p>Alternatively:</p> <pre><code>var m, params = {}, rex = /([A-Z-]+):([\s\S]*?)(?=\s+[A-Z-]+:|$)/g; while ( m = rex.exec( file_content ) ) { params[ m[1] ] = m[2]; } console.log( params["DTSTART"] ); // 20121127T190000Z </code></pre>
 

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