I am having a hell of a time getting my regular expression to match properly, my first regular expression worked well as far as I know, but now that I need to account for a double-digit number, every time I get the output of the match it's only a piece of what I am trying to capture.
First of all my function to capture the groups is here. This function will go through the string, and it will find the Message codes so that I can center my text properly.
My regular expression works fine in this online tester
https://regex101.com/r/mU5jY5/3
The console will output this string, for some reason it won't find the / but replaces it with a C and another strange thing is it's adding a C to the end of the string.
This is what it should look like.
Any help or suggestion would be much appreciated, regular expressions are tough to create when you are just learning about them. Thanks in advanced :)
First of all my function to capture the groups is here. This function will go through the string, and it will find the Message codes so that I can center my text properly.
My regular expression works fine in this online tester
https://regex101.com/r/mU5jY5/3
JavaScript:
Window_Pop.prototype.adjustStringWidth = function(string) {
var widthToRemove = '';
var toDelete = string.match(/([\/\C\N\V\G\I\][\d*])/g);
console.log(toDelete);
if(!toDelete) return 0;
for (var i = 0 ; i < toDelete.length ; i++) {
widthToRemove += toDelete[i];
}
console.log('widthToRemove = ' + widthToRemove);
var removedWidth = this.textWidth(widthToRemove);
return removedWidth;
};
Code:
C[14]C
Code:
\C[14]