简体   繁体   中英

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 . I tried split but need to know correct regular expression.

Example:

input: 22222

output: <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>

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