i have string in javascript:
'nearly 2 pound/12345'
and need check if string match pattern
'some string useless/number'
and number.
i have created regex /\/\d+/g
number,but char '/'.
so how can solve these?
if expression "forward-slash followed numbers", should suffice
let numbers = (/\/(\d+)/.exec(str) || []).pop()
to break down...
create regex forward-slash followed one-or-more digits (that want capture)
let regex = /\/(\d+)/
you may want / need tweak make more specific. example numbers appear @ end of string, use
/\/(\d+)$/
.execute regex against string. either return
null
no match or array entire match @ index 0 , capture group @ index 1, eg["/12345", "12345]
regex.exec(str)
create expression results in array, if no match made
let arr = (regex.exec(str) || [])
use
array.prototype.pop
last array entrylet numbers = arr.pop()
numbers
undefined if there no match.