You're viewing old version number 9. - Current version
Regular Expressions with JavaScript
http://www.w3schools.com/jsref/jsref_match.asp
no \s like in perl, so : use [\s\S]* in regex
http://stackoverflow.com/questions/1068280/javascript-regex-multiline-flag-doesnt-work
http://www.w3schools.com/jsref/jsref_obj_regexp.asp
http://www.regular-expressions.info/javascript.html
http://www.javascriptkit.com/javatutors/redev2.shtml
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
http://www.advanced-javascript-tutorial.com/RegularExpressions.cfm#.UmbpgnBwqSo
Code Example
I assume an easier method exists to do this.
Get TOC info
var txt = "asdfasdf\nasdfasdf\nasdfasdf\n<!-- header:4:11:29 p.m. -->\n<!-- header:4:10:02 p.m. -->\n<!-- header:4:6:11 p.m. -->\nasdfasdf\nasdf";
var res = txt.match(/<!-- header:([1-6]):(.*?) -->/mg);
for (i=0; i<res.length; i++ ) {
console.log('res ' + i + ' = ' + res[i]);
var headers = [];
var regex = /<!-- header:([1-6]):(.*?) -->/m;
if ( headers = regex.exec(res[i]) ) {
for (j=0; j<headers.length; j+=3 ) {
console.log('header 0 = ' + headers[j]);
console.log('header 1 = ' + headers[j+1]);
console.log('header 2 = ' + headers[j+2]);
}
}
}
Output
node regex3.js
res 0 = <!-- header:4:11:29 p.m. -->
header 0 = <!-- header:4:11:29 p.m. -->
header 1 = 4
header 2 = 11:29 p.m.
res 1 = <!-- header:4:10:02 p.m. -->
header 0 = <!-- header:4:10:02 p.m. -->
header 1 = 4
header 2 = 10:02 p.m.
res 2 = <!-- header:4:6:11 p.m. -->
header 0 = <!-- header:4:6:11 p.m. -->
header 1 = 4
header 2 = 6:11 p.m.
From JR's : articles
189 words - 1804 chars
- 1 min read
created on
updated on
- #
source
- versions
Related articles
Regular Expressions with JavaScript - Dec 04, 2014
More JavaScript technologies - Nov 11, 2013
Links feb 25, 2017 - Feb 25, 2017
Cross-Origin Resource Sharing header - Jan 09, 2015
Web and mobile development using Perl, HTML5, CSS3, and JavaScript - May 28, 2013
more >>