To split a JID into its component parts (the localpart, domainpart, and resourcepart), the following algorithm should be used (where the localpart is represented by lp, the resourcepart by rp, and the domainpart by dp and ∈ is used to check if the given character is included in the string):
Note that the localpart and resourcepart are optional and may result in empty strings (you may have a jid that is just a domainpart).