I need to create a regex which should look for the last '*' irrespective of the whitespace in the string. Then, I need to replace that string with some text.
Currently, it is replacing the first occurence of '*' in the string.
How do I fix it?
Here's my code:
const regex = /\*/m;
const str = 'Field Name* * ';
const replaceStr = ' mandatory';
const result = str.replace(regex, replaceStr);
console.log('Substitution result: ', result);
Here, the output should be 'Field Name* mandatory'. But what I get is 'Field Name mandatory *'.