在javascript中使用正则表达式翻译preg_replace .replace [关闭]

I need to translate this php function: $string = preg_replace('/#([a-z0-9]+)/i', '#$1',$string); In an equivalent JavaScript .replace function if it's possible.. Thank you..

JavaScript's replace method is almost identical, but it's a method of string instead of its own function

$string.replace(/#([a-z0-9]+)/i, '#$1');

The only major difference is that JavaScript allows regex literal syntax (with /) so the first argument should not be wrapped in quotes.