Skip to content

Instantly share code, notes, and snippets.

View indexzero's full-sized avatar
🌎
Always bet on Open Source

Charlie Robbins indexzero

🌎
Always bet on Open Source
View GitHub Profile
var html = "<div><hr>foo<div>bar</div></div>";
var c = -1;
html = html.replace(/\<([^<\>]*)\>/g, function(str, r) {
if(r.indexOf("/") === -1) {
c++;
return "[\"" + r + ((c == 0) ? "\"," : "\"],");
Match any well formed tags
(<([^<\>]*)>(.*?)</([^<\>]*)>|<([^<\>]*)/>)
Match any tag (with a couple variations) or anything between tags
(>[^<\>](.*?)<|<([^<\>]*)>|</([^<\>]*)>|<([^<\>]*)/>)
-> First Group (i.e. anything between tags isn't matching in RegexBuddy)
Match any tag (with one variation):
(>[^<\>](.*?)<|<([^<\>]*)>)
-> First Group (i.e. anything between tags isn't matching in RegexBuddy)
var html = "<div><div>foo</div></div>"
var split = html.split(/(<[^<\>]*>)/);
var jup = "";
// Simple state machine:
// 'start' : Last Saw Start Tag
// 'content': Last Saw Content
// 'end' : Last Saw End
Charlies-MacBook-Pro:nodejitsu Charlie$ node
Type '.help' for options.
node> var jsdom = require('jsdom');
###########################################################
# WARNING: node-htmlparser could not be found.
# Element.innerHTML setter support has been disabled
# Element.innerHTML getter support will still function
# Download: http://github.com/davglass/node-htmlparser
###########################################################
Charlies-MacBook-Pro:node-cloudservers Charlie$ vows
·
http:909
parser.finish();
^
TypeError: Cannot call method 'finish' of undefined
at Client.onend (http:909:12)
at IOWatcher.callback (net:495:28)
at node.js:266:9
<SCRIPT TYPE="text/javascript">
var gDomain="sdc.bmi.com";
var gDcsId="dcsnnb9tr9wm1ic8m9wiosd8c_5q1q";
var gFpc="WT_FPC";
function parseQueryString(subject) {
var results = {};
var parser = /[^&\?]+/g;
var match = parser.exec(subject);
while (match != null) {
var parts = match[0].split('=');
results[parts[0]] = parts[1];
match = parser.exec(subject);
}
return results;
var sys = require('sys'),
http = require('http');
process.on('uncaughtException', function (err) {
sys.puts('Caught exception: ' + err);
});
// Simple Example
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var httpAgent = require('http-agent'),
sys = require('sys');
var agent = httpAgent.create('www.google.com', ['finance', 'news', 'images']);
agent.addListener('next', function (agent) {
setTimeout(function () {
sys.puts('Body of the current page: ' + agent.body);
sys.puts('Response we saw for this page: ' + agent.response);
var jsdom = require('jsdom'),
sys = require('sys');
//
// Remark: I have jsdom.createWindow working with complex HTML pages pulled from the wild intertubes :)
//
var window = jsdom.createWindow('<html><body><h1>Hello Server Side jQuery</h1></body></html>');
jsdom.jQueryify(window, '/path/to/jquery.js', function () {
sys.puts(window.jQuery('h1')[0].innerHTML);