diff src/test/tiny.html @ 30:8ff35379cc89

regex cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 25 Jul 2022 22:10:28 -0600
parents d9d7aa2a79db
children 6d265f5e18e2
line wrap: on
line diff
--- a/src/test/tiny.html	Mon Jul 25 21:28:10 2022 -0600
+++ b/src/test/tiny.html	Mon Jul 25 22:10:28 2022 -0600
@@ -10,10 +10,11 @@
 				return '<iframe data-video="'+url+'" width="560" height="315" frameborder="0" allowfullscreen src="'+url+'"></iframe>';
 			}
 
+			// fucking moronic javascript doesn't have \Q \E in regex
 			var videoHandlers = {};
 			{
-				let ptn1 = new RegExp('https://youtu.be/([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+))?');
-				let ptn2 = new RegExp('https://www.youtube.com/watch\\?v=([a-zA-Z0-9_-]+)(?:\\?t=([0-9]+)s)?');
+				let ptn1 = /^https:\/\/youtu\.be\/([a-zA-Z0-9_-]+)(?:\?t=([0-9]+))?/;
+				let ptn2 = /^https:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9_-]+)(?:&t=([0-9]+)s)?/;
 				videoHandlers.youtube = function(url) {
 					let result = url.match(ptn1) || url.match(ptn2);
 					if( result ) {
@@ -25,7 +26,7 @@
 				}
 			}
 			{
-				let ptn = new RegExp('https://rumble.com/embed/[a-z0-9]+/\\?pub=[a-z0-9]+');
+				let ptn = /^https:\/\/rumble\.com\/embed\/[a-z0-9]+\/\?pub=[a-z0-9]+/;
 				videoHandlers.rumble = function(url) {
 					if( url.match(ptn) ) {
 						return videoIframe(url);
@@ -33,7 +34,7 @@
 				}
 			}
 			{
-				let ptn = new RegExp('https://www.bitchute.com/video/([a-zA-Z0-9]+)/');
+				let ptn = /^https:\/\/www\.bitchute\.com\/video\/([a-zA-Z0-9]+)\//;
 				videoHandlers.bitchute = function(url) {
 					let result = url.match(ptn);
 					if( result ) {
@@ -43,7 +44,7 @@
 				}
 			}
 			{
-				let ptn = new RegExp('https://vimeo.com/([0-9]+)');
+				let ptn = /^https:\/\/vimeo\.com\/([0-9]+)/;
 				videoHandlers.vimeo = function(url) {
 					let result = url.match(ptn);
 					if( result ) {
@@ -53,7 +54,7 @@
 				}
 			}
 			{
-				let ptn = new RegExp('https://dai.ly/([a-z0-9]+)');
+				let ptn = /^https:\/\/dai\.ly\/([a-z0-9]+)/;
 				videoHandlers.dailymotion = function(url) {
 					let result = url.match(ptn);
 					if( result ) {
@@ -63,7 +64,7 @@
 				}
 			}
 			{
-				let ptn = new RegExp('https://www.tiktok.com/[^/]+/video/([0-9]+)');
+				let ptn = /^https:\/\/www\.tiktok\.com\/[^/]+\/video\/([0-9]+)/;
 				videoHandlers.tiktok = function(url) {
 					let result = url.match(ptn);
 					if( result ) {
@@ -74,7 +75,7 @@
 				}
 			}
 			{
-				let ptn = new RegExp('\\.[a-zA-Z0-9]+$');
+				let ptn = /\.[a-zA-Z0-9]+$/;
 				videoHandlers.file = function(url) {
 					if( url.match(ptn) ) {
 						return '<video controls width="560" height><source src="'+url+'"></video>';