Eric David Eric David - 1 year ago 113
Javascript Question

Regular expression to read only digits after last slash

I'm trying to read the numbers after the last \ using regular expressions but unable to do it.

I've tried using

but both don't work. The first one removes the numbers.

Please can you advice?

My sample data is:


Answer Source

In JS, you may use


See the regex demo

The \\(\d+)$ regex matches:

  • \\ - a literal \ symbol
  • (\d+) - Group 1: one or more digits
  • $ - end of string.

var path = "C:\\Users\\Documents\\Projects\\Austraila\\Customer\\Organisation\\176276";
var m = path.match(/\\(\d+)$/);
if (m) {

Lua solution:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download