0

I need to detect if a user enters in an input the characters pl and a .

Something like this pl.68768768 this pl67687678 or this .6897987

Get it? Whatever is there I should always remove pl., pl or just ..

I was trying to do it with .includes like theString.includes('pl.'), but how can I do it with a regex so it is more dynamic?

Non
  • 7,689
  • 14
  • 55
  • 110

1 Answers1

-1

Basic reg expression

function cleanPl(str){
  return str.replace(/^(pl)?\.?/,'');
}

console.log(cleanPl("pl.68768768"));
console.log(cleanPl("pl68768768"));
console.log(cleanPl(".68768768"));
console.log(cleanPl("68768768"));

Visualize it

epascarello
  • 185,306
  • 18
  • 175
  • 214