INSR-10111: Use regex in mapStringToPhoneNumber
This commit is contained in:
parent
87e04ad178
commit
d106ebb9d7
1 changed files with 3 additions and 14 deletions
|
|
@ -326,20 +326,9 @@ function mapStringToState(str) {
|
|||
* @param str
|
||||
*/
|
||||
export function mapStringToPhoneNumber(str) {
|
||||
const startIndex = str.indexOf(`{${dynamicStrings.PHONE_NUMBER}`);
|
||||
|
||||
let textToReplace = str.substring(startIndex, str.length);
|
||||
textToReplace = textToReplace.substring(0, textToReplace.indexOf('}') + 1);
|
||||
|
||||
const phoneNumber = textToReplace.substring(
|
||||
dynamicStrings.PHONE_NUMBER.length + 2,
|
||||
textToReplace.length - 1
|
||||
);
|
||||
const displayPhoneNumber = toDisplayPhoneNumber(phoneNumber);
|
||||
|
||||
const returnVal = str.replace(textToReplace, displayPhoneNumber);
|
||||
|
||||
return returnVal;
|
||||
// Expected token format: {phoneNumber:##########} (or 11 digits).
|
||||
const regexExp = new RegExp(`\\{${dynamicStrings.PHONE_NUMBER}:([^{}]*?)\\}`, 'g');
|
||||
return str.replace(regexExp, (_match, phoneNumber) => toDisplayPhoneNumber(phoneNumber));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue