JSFiddle - React, Tailwind, and code Playground

by Jake

JavaScript

const findMatchingAttributeVal = function(tag, att, text){
							//		\[tag[^\]]*	     matches opening of shortcode tag 
							//		att="([^"]*)"    captures value inside " and "
							var re = new RegExp(`\[${tag}[^\]]* ${att}="([^"]*)"`, 'i');
              console.log(re);
							var result = text.match(re);
              //console.log(result);
							if( result != null && result.length > 0 )
								return result[1];
							//		\[tag[^\]]*	     matches opening of shortcode tag 
							//		att="([^"]*)"    captures value inside ' and ''
							re = new RegExp(`[${tag}[^\]]* ${att}='([^']*)'`, 'i');
							result = text.match(re);
							if( result != null && result.length > 0 )
								return result[1];
							//		\[tag[^\]]*	     matches opening of shortcode tag 
							//		att="([^"]*)"    captures a shortcode value provided without quotes, 
							//		                   as in [me color=green]
							re = new RegExp(`\[${tag}[^\]]* ${att}=([^\s]*)\s`, 'i');
							result = text.match(re);
							if( result != null && result.length > 0 )
								return result[1];
							return '';
						};
const isAttributePresent = function(tag, att, text){
							//		\[tag[^\]]*	     matches opening of shortcode tag 
							//		att[=\s]+?       matches the attribute either followed by a space
							//		                   (to differentiate cat from catnip) or by an =
							//		                   as in cat="dumb"
							//		[^\]]*]          matches the end bracket of the opening shortcode tag
							const re = new RegExp(`\\[${tag}[^\\]]* ${att}[=\\s\\]]`, 'i');
      //				const re = new RegExp(`\\[${tag} ${att}[=\\s\\]]`, 'im');

							console.log(re);
							return re.test(text);
						};
var hasShortcode = function(text, tag=false){
	if( tag === false )
  	var re = new RegExp(/\[[a-z][a-z0-9]{1,}/);
  else
		var re = new RegExp(`\\[${tag} `, 'i');
  return re.test( text );
}

var text = `btn ttl="Blah Blah Blah, baby doo" start="open" color=green
[]
<em><strong>It...