Wikipedia talk:WikiProject JavaScript: Difference between revisions
Content deleted Content added
Line 243:
I'm stuck! I look forward to your replies. [[User talk:The Transhumanist|<i>The 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 in the replacement string [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> <span style="font-size:95%;">[[[d:w:User talk:Evad37|talk]]]</span> 04:59, 7 May 2017 (
:: {{ping|Evad37}} What about <code>var patt3 = new RegExp("$1\*");</code>. Will that work? [[User talk:The Transhumanist|<i>The Transhumanist</i>]] 23:03, 7 May 2017 (UTC)
== Use of Wikipedian programmer categories ==
|