I am retrieving a push token using expo push notifications that looks like this
ExponentPushToken[rPCD4qJ_yJr0fkxoELSEk3]
I’d like to access only the number itself rPCD4qJ_yJr0fkxoELSEk3 so I can use it as a temporal user ID before the user signs up, but I’m not sure if this is possible to do.
Any solutions out there to do this that I’m missing?
I’ll leave it to you to google the exact syntax, but you should be able to use a JavaScript regular expression to get everything between the two brackets.
let start = token.indexOf("[");
let end = token.indexOf("]");
if (start >= 0 && end > start) {
console.log(token.slice(start + 1, end));
} else {
console.log("Invalid token?");
}
Both of the snippets above assume the token is in the correct format. If some random string is used instead they might return nonsense or might log “Invalid token?”.