In ruby, I often use something like this:
if "my string123" =~ /string(\d+)/
puts "I got #{$1}"
end
How would I do something similar in javascript? Currently, I've been doing this but it feels dirty.
m = "my string123".match(/string(\d+)/)
if (m)
puts "I got " + m[1]
Perhaps I should just live with this, but thought I'd ask if there was a syntax subtelty I was missing. Thanks!
/regexp/g. Then your match will be returned inm[0].m, it should probably have thevarkeyword:var m = ...;. Also, I don't think JavaScript hasputs./gflag: you'd get"string123", not"123"`, you're forgetting about the group.