Posts

Showing posts with the label safe

Literal Regular Expression Safe Regular Expression

... sorry for the redundant title but that's exactly what is this post about ... after yesterday explanation about problem, logic, and solution, to grab valid strings inside JS code, here I am with the literal RegExp able to grab literals RegExps in a generic JavaScript code. Why Do Not Add Just A "/" Into Other Strings RegExp One comment gave me the hint to write this second post about RegExps. While time is a bit over during days, this answer is simple, but not obvious! Differences between strings and literal regular expressions are basically these: there must be at least one char, or the parser will consider the literal RegExp an inline comment // the slash does NOT necessary need to be escaped. If we have a slash inside a range [a/b] the latter one won't break the RegExp and the slash will be considered just one valid char in that range there could be one or more chars after, where i(ignore case), g(match all), and m(multi line) can be present one or more times L...

String Escape Safe Regular Expression

I should have probably investigated more but apparently I did it ... the most problematic I've encountered so far with JavaScript RegExp seems to be solved! Update Indeed, I should have investigated ... I just like to find solutions by my own. I am not surprised somebody already investigated this classic parsing problem. Steve talked about it a year ago, using the lookbehind missed feature I talked in this post. Above post has much more details than mine (and much more Edits as well). The good part I am happy about is that both me and Steve came out with basically the same solution, but His one is definitively more compact: // Steves Levithan compact solution /(["'])(?:(?=(\\?))\2.)*?\1/g The assumption of above regexp is that if there is a char followed by an escape one, there must be another char that cannot be the initial single or double quote, being the latter one outside the second un captured part, and after a non greedy operation. If the second condition, \2, does...

en-code: the quickest way to encode your snippet

Update I have created an inline callback that could be used to show en-code in every page or as bookmark: WebReflection::encode (just a click to give it a try) javascript:(function(src,w,h,i,s){if(this.WebReflectionEncode)return this.WebReflectionEncode();function p(){s.top=(document.documentElement.scrollTop||(document.body&&document.body.scrollTop)||0)+'px'};try{i=document.createElement('<iframe frameborder="0" src="'+src+'"></iframe>')}catch(e){i=document.createElement('iframe');i.src=src};s=i.style;s.border='1px solid black';s.width=w+'px';s.height=h+'px';s.position='absolute';s.right=0;s.zIndex=99999;p();w=setInterval(p,250);(document.body||document.documentElement).appendChild(i);this.WebReflect...