Extract the filename from a URL
var regexp = /(\w|[-.])+$/ str = document.URL a = regexp.exec(str) alert(a[0])
Reference: Regular Expressions: Methods - Doc JavaScript [webreference.com]
11332 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
var regexp = /(\w|[-.])+$/ str = document.URL a = regexp.exec(str) alert(a[0])
DateAdd("d", -1.0 * DatePart("d", Today), Today)
DateAdd("D", -1.0 * DatePart("D", Today) + 1, Today)
DateAdd("D", -1.0 * DatePart("D", Today) + 1, DateAdd("m", -1, Today))
#include <iostream> #include <string> #include <map> #include <cctype> char look; std::map<std::string, int> table; void getChar() { look = std::cin.get(); } void error(const std::string &s) { std::cout << std::endl; std::cout << "Error: " << s << "." << std::endl; } void abort(const std::string &s) { error(s); exit(1); } void expected(const std::string &s) { abort(s + " Expected"); } bool isAlpha(char c) { return isalpha(c); } bool isDigit(char c) { return isdigit(c); } bool isAlNum(char c) { return isalnum(c); } bool isAddop(char c) { return ((c == '+') || (c == '-')); } bool isMulop(char c) { return (('*' == c) || ('/' == c)); } bool isWhite(char c) { return ((' ' == c) || ('\t' == c)); } void skipWhite() { while (isWhite(look)) getChar(); } void match(char x) { if (look != x) expected(std::string("\"") + x + "\""); else { getChar(); skipWhite(); } } void emit(const std::string &s) { std::cout << "\t" << s; } void emitLn(const std::string &s) { emit(s); std::cout << std::endl; } void newLine() { if (look == '\n') getChar(); } std::string getName() { if (!isAlpha(look)) expected("Name"); std::string name; while (isAlNum(look)) { name += look; getChar(); } skipWhite(); return name; } int getNum() { int value(0); if (!isDigit(look)) expected("Integer"); while (isDigit(look)) { value = value * 10 + look - '0'; getChar(); } skipWhite(); return value; } int expression(); int factor() { int ret; if (look == '(') { match('('); ret = expression(); match(')'); } else if (isAlpha(look)) { std::string name = getName(); if (table.count(name) == 0) table.insert(std::pair<std::string, int>(name, 0)); ret = table[name]; } else ret = getNum(); return ret; } int term() { int value = factor(); while (isMulop(look)) { if (look == '*') { match('*'); value *= factor(); } else if (look == '/') { match('/'); value /= factor(); } } return value; } int expression() { int value(0); if (!isAddop(look)) value = term(); while (isAddop(look)) { if (look == '+') { match('+'); value += term(); } else if (look == '-') { match('-'); value -= term(); } } return value; } void assignment() { std::string name = getName(); match('='); if (table.count(name) == 1) table[name] = expression(); else table.insert(std::pair<std::string, int>(name, expression())); std::cout << name << " = " << table[name] << std::endl; } void init() { getChar(); skipWhite(); } int main(int argc, char *argv[]) { init(); do { assignment(); newLine(); } while ((look != '.') && (look != '\n')); return 0; }
function inorder(T) { if ((T.cargo == '+') || (T.cargo == '-') || (T.cargo == '*') || (T.cargo == '/')) return [].concat(inorder(T.left)).concat(T.cargo).concat(inorder(T.right)); return new Array(T.cargo); } function preorder(T) { if ((T.cargo == '+') || (T.cargo == '-') || (T.cargo == '*') || (T.cargo == '/')) return [].concat(T.cargo).concat(preorder(T.left)).concat(preorder(T.right)); return new Array(T.cargo); } function postorder(T) { if ((T.cargo == '+') || (T.cargo == '-') || (T.cargo == '*') || (T.cargo == '/')) return [].concat(postorder(T.left)).concat(postorder(T.right)).concat(T.cargo); return new Array(T.cargo); } function Tree(cargo, left, right) { this.cargo = cargo; this.left = left; this.right = right; } function split(s) { var r = []; var cur = ''; for (var i = 0; i < s.length; ++i) { var c = s.charAt(i); if ((c == '+') || (c == '-') || (c == '*') || (c == '/') || (c == '(') || (c == ')')) { cur.replace(" ", ""); if (cur.length > 0) { r.push(cur); cur = ''; } r.push(c); } else { cur += c; } } if (cur.length > 0) r.push(cur); return r; } function getToken(tokens, expected) { if (tokens[0] == expected) { tokens.splice(0, 1); return true; } return false; } function getVar(tokens) { if (getToken(tokens, '(')) { var a = getSum(tokens); getToken(tokens, ')'); return a; } else { var aux = tokens[0]; tokens.splice(0, 1); return new Tree(aux, undefined, undefined); } } function getProduct(tokens) { var a = getVar(tokens); if (getToken(tokens, '*')) { var b = getProduct(tokens); return new Tree('*', a, b); } else if (getToken(tokens, '/')) { var b = getProduct(tokens); return new Tree('/', a, b); } return a; } function getSum(tokens) { var a = getProduct(tokens); if (getToken(tokens, '+')) { var b = getSum(tokens); return new Tree('+', a, b); } else if (getToken(tokens, '-')) { var b = getSum(tokens); return new Tree('-', a, b); } return a; } function evalExp(s) { var tokens = split(s); //alert(tokens); return t = getSum(tokens); }