In this example, the string is:
draggable ui-draggable ui-draggable-handle dragged col-lg-8
Instead of matching individual characters (using []
), you want to match the exact string col-lg-#
. To achieve this and capture only the number, enclose \d+
in a capture group, which can be retrieved using .match()
.
/col-lg-(\d+)/
This pattern should suit your requirement better.
To implement this in a script:
var example = 'draggable ui-draggable ui-draggable-handle dragged col-lg-8';
var colNum = example.match(/col-lg-(\d+)/)[1];
console.log(colNum);
// Output: 8