You can either get the value from UserSettings.txt (although unsure whether its value ingame reflects your current server or the previous one), or from add-on filter:
Lua Code:
local realm = GetCVar("LastRealm")
local realm_dash_char = GetAddOnManager():GetAddOnFilter()