Skip to content

Instantly share code, notes, and snippets.

@meto4d meto4d/thread_regexp.js
Last active Mar 26, 2020

Embed
What would you like to do?
//汎用URLパターン
var URL_PATTERN = /^(\w+):\/\/((\w|\.|:)+)(\/(.*))?$/
//したらば
var SHITARABA_URL_PATTERN = /^https?:\/\/jbbs\.shitaraba\.net.*$/
var SHITARABA_THREAD_URL_PATTERN = /^https?:\/\/jbbs\.shitaraba\.net\/bbs\/read\.cgi\/(\w+)\/(\d+)\/(\d+)(:?|\/.*)$/;
var SHITARABA_BOARD_URL_PATTERN = /^https?:\/\/jbbs\.shitaraba\.net\/(\w+)\/(\d+)\/?$/;
//2ch系列
var NICHAN_THREAD_URL_PATTERN = /^https?:\/\/(?!jbbs\.shitaraba\.net)(.+)\/test\/read\.cgi\/(\w+)\/(\d+)\/(:?|\/.*)$/;
var NICHAN_BOARD_URL_PATTERN = /^https?:\/\/(?!jbbs\.shitaraba\.net)(.+)\/(\w+)\/?$/;
//複合汎用掲示板
var THREAD_URL_PATTERN = /^(\w+):\/\/([^\/]+)\/(test|bbs)\/read\.cgi\/(\w+)\/(\d+)(\/(\d+))?(:?|\/.*)$/;
var BOARD_URL_PATTERN = /^(\w+):\/\/([^\/]+)\/(\w+)(\/(\d+))?\/?$/;
var match = THREAD_URL_PATTERN.exec(CONTACT_URL);
function thread_url(match) {
var url = {};
url.protocol = match[1];
url.shitaraba = ~match[2].indexOf("shitaraba");
url.fqdn = match[2];
url.category = match[4];
url.board_num = url.shitaraba ? match[5] : "";
url.thread_id = url.shitaraba ? match[7] : match[5];
return url;
}
var match = BOARD_URL_PATTERN.exec(CONTACT_URL);
function board_url(match) {
var url = {};
url.protocol = match[1];
url.shitaraba = ~match[2].indexof("shitaraba");
url.fqdn = match[2];
url.category = match[3];
url.board_num = url.shitaraba ? match[5] : "";
return url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.