早い話、Perlにおけるquotemeta
があればOK、と。
という感じで、バックスラッシュをいっぱい書かなければいけないので
perldoc -f quotemeta
- quotemeta
Returns the value of EXPR with all non-"word" characters backslashed. (That is, all characters not matching
/[A-Za-z_0-9]/
will be preceded by a backslash in the returned string, regardless of any locale settings.) This is the internal function implementing the\Q
escape in double-quoted strings.
なら、話は簡単。
- String:
- Quotemeta:
String.prototype.quotemeta = function(){ return this.replace(/([^0-9A-Za-z_])/g, '\\$1'); }
で、ぐぐると前に作ってましたね。
Enjoy!
Dan the Wheel Re-inventor
このブログにコメントするにはログインが必要です。
さんログアウト
この記事には許可ユーザしかコメントができません。