Wikipedia talk:WikiProject JavaScript: Difference between revisions

Content deleted Content added
Nested RegExp: refine reply
Line 238:
 
I'm stuck! I look forward to your replies. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 23:00, 6 May 2017 (UTC)
:Your patt3 is off for a couple of reasons. First, with the $''n'' regex matches, in general you access them using <code>RegExp.$1</code> (which will be a string containing the match), not just <code>$1</code> – except for within String.replace function, when just <code>$1</code> is used [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n]. Secondly, with regex literals, what you type is literally what you get as the regex string. So <code>var patt3 = /$1\*/;</code> will literally be interpreted as <code>/$1\*/</code> (where <code>$</code> asserts position at the end of the string; <code>1</code> matches the character <code>1</code>; <code>\*</code> matches the character <code>*</code>).
:What you could use instead is <code>var patt3 = new RegExp("\\*{"+(RegExp.$1.length+1)+"}");</code> which, for example, will give you the regex <code>/\*{3}/</code> when the <code>RegExp.$1</code> match is "**" - <u>'''[[User:Evad37|Evad]]''37'''''</u>&nbsp;<span style="font-size:95%;">&#91;[[d:w:User talk:Evad37|talk]]]</span> 04:59, 7 May 2017 (UTC)
 
== Use of Wikipedian programmer categories ==