开发者

javascript regex questions

I have a used a javascript replace to wrap all words seperated by a space, but it does only wrap numbers 开发者_如何学运维and letters, but i want it to wrap every character like dots, comma's, quotes etc

i have used this regex pattern

string.replace(/\b([\w+-]+)\b/g,'<b>$1</b>')


If you want to wrap anything that isn't a space, make your regex match everything that isn't a space. Try this one:

/([^\s]+)/g


Am I missing something here, or wouldn't

'<b>' + string + '</b>'

suffice?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜