简体   繁体   中英

Javascript equivalent regular expressions

Whats the javascript equivalent of

$tring="I love my #newJob";

preg_replace('/(#)(\w+)/i', '<a href="index.php?mod=tags&id=\2">\1\2</a>', $tring);

Almost same except: backreferences are $n form instead of \\n , using regular expression literal instead of string.

string = "I love my #newJob";
string.replace(/(#)(\w+)/i, '<a href="index.php?mod=tags&id=$2">$1$2</a>')
// => "I love my <a href="index.php?mod=tags&id=newJob">#newJob</a>"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM