0

I am trying to extract letters and integers from a itemValue in JS.The itemValue is fetched from a class.

@wire(ItemDetail, { itId: '$itemId' })
    wiredItemDetail({data,error}){
        if (data) {
            this.itemValue=data.itemValue;
       }

how can be this done?

letterChk = /[a-z]/i.exec(itemValue);
value =.itemValue.slice(letterCheck.index);

please help

1
  • 1
    What is the purpose for extraction?
    – MnZ
    Jun 26 at 10:02

1 Answer 1

0

you can try something like this:

let myString = 'a%b^c-d+e?123A2B';
let regex = /[^a-z]/gi;
let regexNums = /[^0-9]/g;
let result = myString.replace(regex, '');
let resultNums = myString.replace(regexNums, '');
console.log('result: %O', result) // prints: abcdeAB
console.log('resultNums: %O', resultNums) // prints: 1232

Not the answer you're looking for? Browse other questions tagged or ask your own question.