Firebase push Id: What characters can be inside?

Viewed 3042

For an app I build, I want to use the ID generated by Firebase push as an email address local part. Since the dash (-) is not allowed as first character, I would like to replace it with another character.

This has to be reversible though. Therefore I want to know, which characters does the Firebase push ID consist of? So far I have seen:

  • alpha (a-z and A-Z and 0-9)
  • underscore (_)
  • dash (-)

Sample: -KD3rcGMuucRDjKOTK3O

  • Are there any other characters which might be contained in the ID?
  • Do firebase IDs always start with a dash?
2 Answers

Not strictly a response to the question asked but related: based on @Frank's answer above it seems like a regex that will always match a Firebase push ID will look something like this:

const regex = /[a-zA-Z0-9-_;]*/gm;

This regex assumes that the ID in the string will be delimited by /. The - and ; added to cover the remaining character set. Remove the gm pattern flags if you are only after the first match.

I had a problem where I needed to extract the push ID from an URL. The push ID appeared after another known ID. The regex for such a situation can look like this:

let regex = new RegExp(`(?<=${known_ID}\/)[a-zA-Z0-9-_;]*`);
Related