regex - JavaScript - Remove Minecraft Color Codes from String -


i'm trying remove minecraft color codes string:

[§aannouncement§r] §4test 

and searched here, tried own, no avail.

code:

module.exports.regextest = function (message) {     var regex = '(?i)§[0-9a-fk-or]/g';     return message.replace(regex,''); }; 

now, accounts tells me that regular expression works, when parse message in post doesn't remove anything.

what wrong regex code?

edit: @anubhava help. turns out source recieving sending wrong unicode. fixed code:

console.log(message.replace(/\u00a7[0-9a-fk-or]/ig,'')); 

thanks help, everyone!

(?i) not supported in javascript regex, try regex:

var regex = /\u00a7[0-9a-fk-or]/ig; 

demo


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -