Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get the first string's from the right hand side

So I have this code that would get the first string’s from the right hand side and stop whenever there is an integer but for some reason its not working with me.

Example input of fUnit is "CS_25x2u"

expected output of it after using unit is "u".

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Real output is "undefined".

function buildUnit(fUnit){// wahts ginna be passed here is the gibirish unit and the output of this function is the clear unit
    fUnit = fUnit.toString;
    const regex = /[a-zA-Z]*$/;
    const unit = (x) => x.match(regex)[0];
    fUnit = unit(fUnit);

If you need more info please let me know

Thank you

>Solution :

const regex = /[a-zA-Z]*$/;
console.log(regex.exec(sample));

Assuming fUnit variable contains your string

const unit = (x) => x.match(regex)[0];
console.log(unit(fUnit));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading