Regex for grabbing payload from javascript NDEF tag -


i have string generated nfc ndef payload, below:

string:

enmac_98:d3:36:00:a2:90

from this:

var macdevicex = string(finalndef.match(/mac_(.*)/));

i want grab text after mac_ part of string. getting string below instead. need text after comma text generated below match() above. dont want have match divide comma section, can in 1 match()

getting wrong text:

mac_98:d3:36:00:a2:90,98:d3:36:00:a2:90

you need captured value string, not whole match.

with string#match , regex without global modifier g, array containing [0] whole match , [1] captured value 1 ... [n] captured value n.

return value

an array containing entire match result , parentheses-captured matched results; null if there no matches.

the best way use check if there match @ first, , access 2nd element.

var macdevicex = (m = "enmac_98:d3:36:00:a2:90".match(/mac_(.*)/)) ? m[1] : "";  console.log(macdevicex);

here, assign match result m, , if there match, m[1] (the group 1 capture value) returned, else, "" empty string returned.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -