0

I can't seem to find the issue with this code:

const regex = "/tel:\+61(\d+)/g";
const subscriberNumber = senderAddress.match(regex);

For input text, senderAddress = tel:+619123456789 the subscriberNumber is null.

What's causing it to return null?

quarks
  • 33,478
  • 73
  • 290
  • 513
  • basically, the goal is to remove the "tel:+(area_code)" – quarks Feb 12 '21 at 04:48
  • `const regex = "/tel:\+61(\d+)/g";` is not a regex, and doesn't contain any backslashes, either - it's equivalent to `/tel:+61` etc. If you want a regex, use `new RegExp` (and double-escape the backslashes) or, even better, use a regex literal `const regex = /tel:\+61(\d+)/` (drop the global flag) – CertainPerformance Feb 12 '21 at 04:50

2 Answers2

-1

You haven't escaped the + in 61. + is used as a concatenation operator too.

Shahab Uddin
  • 101
  • 1
  • 11
-1

I don’t think the parentheses around \d+ are necessary.

JTorres
  • 24
  • 2