简体   繁体   English

Javascript正则表达式-使用正则表达式拆分字符串

[英]Javascript regex - split string with regular expression

I need to style my JavaScript number string so would it be possible I can convert/split string and assign style . 我需要设置JavaScript数字字符串的样式,以便可以转换/分割字符串并分配样式。 I tried split but need to know correct regular expression. 我试过split但需要知道正确的正则表达式。

Example: 例:

input: 22222 输入: 22222

output: <p>2</p><p>2</p><p>2</p><p>2</p><p>2</p> 输出: <p>2</p><p>2</p><p>2</p><p>2</p><p>2</p>

Thanks 谢谢

'22222'.split('').map(function(x) {
    return '<p>'+x+'</p>';
}).join('');

Output : <p>2</p><p>2</p><p>2</p><p>2</p><p>2</p> 输出<p>2</p><p>2</p><p>2</p><p>2</p><p>2</p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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