0

正規表現の初心者として、私は次のタスクを達成するために正規表現を構築することができません:

文字列:

(q[1]="one" and q[2]="two")

望ましい結果:

(q[1].indexOf("one") and q[2].indexOf("two"))

したがって、正規表現は、任意の文字とそれに続く文字の組み合わせに置き換える必要=".indexOf("あり"ます")

助けてくれてありがとう!

4

2 に答える 2

3
var str = '(q[1]="one" and q[2]="two")';
str = str.replace(/=("[^"]+")/g, '.indexOf($1)')

これは str を

(q[1].indexOf("one") and q[2].indexOf("two"))
于 2013-06-21T13:57:41.917 に答える