All tutorials
Detecting if text is in the format of a what3words address using RegEx
This tutorial aims to guide you through the process of using Regular Expressions (RegEx) to identify and verify what3words addresses in text strings.
var regex = /(?:\b(?:https?:\/\/)?(?:www\.)?(?:what3words\.com|w3w\.co)\/((?:(?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)){2}(?:\p{L}\p{M}*)+|(?:\p{L}\p{M}*)+(?:[\u0020\u00A0](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\u0020\u00A0](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\u0020\u00A0](?:\p{L}\p{M}*)+){1,3})(?!\/)(?=$|[?#]|[^\p{L}\p{M}]))|(?:(?:^|(?<!\p{L}))\/{0,3}((?:(?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)){2}(?:\p{L}\p{M}*)+|(?:\p{L}\p{M}*)+(?:[\u0020\u00A0](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\u0020\u00A0](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\u{0020}\u00A0](?:\p{L}\p{M}*)+){1,3})(?!\/)(?=$|[?#]|[^\p{L}\p{M}]))/gu;
String regex = "(?:\\b(?:what3words\\.com|w3w\\.co)/((?:(?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+)|(?:(?:\\p{L}\\p{M}*)+(?:[ ](?:\\p{L}\\p{M}*)+){1,3})[.。。・・︒។։။۔።।](?:(?:\\p{L}\\p{M}*)+(?:[ ](?:\\p{L}\\p{M}*)+){1,3})[.。。・・︒។։။۔።।](?:(?:\\p{L}\\p{M}*)+(?:[ ](?:\\p{L}\\p{M}*)+){1,3}))(?![.。。・・︒។։။۔።।]\\p{L})(?=$|[^\\p{L}/\\.\\。。・・︒។։။۔።।]|[.。。・・︒។։။۔።।](?!\\p{L})))|(?:(?:^|(?<!\\p{L}))/{0,3}((?:(?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+)|(?:(?:\\p{L}\\p{M}*)+(?:[ ](?:\\p{L}\\p{M}*)+){1,3})[.。。・・︒។։။۔።।](?:(?:\\p{L}\\p{M}*)+(?:[ ](?:\\p{L}\\p{M}*)+){1,3})[.。。・・︒។։။۔።।](?:(?:\\p{L}\\p{M}*)+(?:[ ](?:\\p{L}\\p{M}*)+){1,3}))(?![.。。・・︒។։။۔።।]\\p{L})(?=$|[^\\p{L}/\\.\\。。・・︒។։။۔።।]|[.。。・・︒។։။۔።।](?!\\p{L})))";
regex = r"(?:(?<=\b(?:what3words\.com|w3w\.co)/)|(?<![\p{L}/\.。。・・︒។։။۔።。]))/*((?:(?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+)|(?:(?:\p{L}\p{M}*)+(?:[ \u00A0](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[ \u00A0](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[ \u00A0](?:\p{L}\p{M}*)+){1,3}))(?![.。。・・︒។։။۔።。/]|\p{L})"
regex = "(?:\\b(?:what3words\\.com|w3w\\.co)/((?:(?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+)|(?:(?:\\p{L}\\p{M}*)+(?:[\u{20}\u{A0}](?:\\p{L}\\p{M}*)+){1,3})[.。。・・︒។։။۔።।](?:(?:\\p{L}\\p{M}*)+(?:[\u{20}\u{A0}](?:\\p{L}\\p{M}*)+){1,3})[.。。・・︒។։။۔።।](?:(?:\\p{L}\\p{M}*)+(?:[\u{20}\u{A0}](?:\\p{L}\\p{M}*)+){1,3}))(?![.。。・・︒។։။۔።।]\\p{L})(?=$|[^\\p{L}/\\.\\。。・・︒។։။۔።।]|[.。。・・︒។։။۔።।](?!\\p{L})))|(?:(?:^|(?<!\\p{L})){0,3}((?:(?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+)|(?:(?:\\p{L}\\p{M}*)+(?:[\u{20}\u{A0}](?:\\p{L}\\p{M}*)+){1,3})[.。。・・︒។։။۔።।](?:(?:\\p{L}\\p{M}*)+(?:[\u{20}\u{A0}](?:\\p{L}\\p{M}*)+){1,3})[.。。・・︒។։။۔።।](?:(?:\\p{L}\\p{M}*)+(?:[\u{20}\u{A0}](?:\\p{L}\\p{M}*)+){1,3}))(?![.。。・・︒។։။۔።।]\\p{L})(?=$|[^\\p{L}/\\.\\。。・・︒។։။۔።।]|[.。。・・︒។։။۔።।](?!\\p{L})))"
NSString *regex = @"(?:\\b(?:what3words\\.com|w3w\\.co)/((?:(?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+)|(?:(?:\\p{L}\\p{M}*)+(?:[ ](?:\\p{L}\\p{M}*)+){1,3})[.。。・・︒។։။۔።।](?:(?:\\p{L}\\p{M}*)+(?:[ \u00A0](?:\\p{L}\\p{M}*)+){1,3})[.。。・・︒។։။۔።।](?:(?:\\p{L}\\p{M}*)+(?:[ \u00A0](?:\\p{L}\\p{M}*)+){1,3}))(?![.。。・・︒។։။۔።।]\\p{L})(?=$|[^\\p{L}/\\.\\。。・・︒។։။۔።।]|[.。。・・︒។։။۔።।](?!\\p{L})))|(?:(?:^|(?<!\\p{L})){0,3}((?:(?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+)|(?:(?:\\p{L}\\p{M}*)+(?:[ \u00A0](?:\\p{L}\\p{M}*)+){1,3})[.。。・・︒។։။۔።।](?:(?:\\p{L}\\p{M}*)+(?:[ \u00A0](?:\\p{L}\\p{M}*)+){1,3})[.。。・・︒។։။۔።।](?:(?:\\p{L}\\p{M}*)+(?:[ \u00A0](?:\\p{L}\\p{M}*)+){1,3}))(?![.。。・・︒។։။۔።।]\\p{L})(?=$|[^\\p{L}/\\.\\。。・・︒។։။۔።।]|[.。。・・︒។։။۔።।](?!\\p{L})))";
$regex = '/(?:\b(?:https?:\/\/)?(?!www\.)?(?!what3words\.com|w3w\.co)\/((?:(?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)){2}(?:\p{L}\p{M}*)+|(?:\p{L}\p{M}*)+(?:[\x{20}\x{A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\x{20}\x{A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\x{20}\x{A0}](?:\p{L}\p{M}*)+){1,3})(?!\/)(?=$|[?#]|[^\p{L}\p{M}]))|(?:(?:^|(?<!\p{L}))\/{0,3}((?:(?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)){2}(?:\p{L}\p{M}*)+|(?:\p{L}\p{M}*)+(?:[\x{20}\x{A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\x{20}\x{A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\x{20}\x{A0}](?:\p{L}\p{M}*)+){1,3})(?!\/)(?=$|[?#]|[^\p{L}\p{M}]))/u';
var regex = new Regex(@"(?:(?<=\b(?:what3words\.com|w3w\.co)/)|(?<![\p{L}/\.\。。・・︒។։။۔።।]))/*((?:(?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+)|(?:(?:\p{L}\p{M}*)+(?:[\u0020\u00A0](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\u0020\u00A0](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\u0020\u00A0](?:\p{L}\p{M}*)+){1,3}))(?![.。。・・︒។։။۔።。]\p{L})(?=$|[^\p{L}/\.\。。・・︒។։။۔።。]|[.。。・・︒។։။۔።।](?!\p{L}))");
regex = /(?:\b(?:what3words\.com|w3w\.co)\/((?:(?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+)|(?:(?:\p{L}\p{M}*)+(?:[\u{0020}\u{00A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\u{0020}\u{00A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\u{0020}\u{00A0}](?:\p{L}\p{M}*)+){1,3}))(?![.。。・・︒។։။۔።。]\p{L})(?=$|[^\p{L}\/\.。。・・︒។։။۔።。]|[.。。・・︒។։။۔።।](?!\p{L})))|(?:(?:^|(?<!\p{L}))\/{0,3}((?:(?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+)|(?:(?:\p{L}\p{M}*)+(?:[\u{0020}\u{00A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\u{0020}\u{00A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[\u{0020}\u{00A0}](?:\p{L}\p{M}*)+){1,3}))(?![.。。・・︒។։။۔።。]\p{L})(?=$|[^\p{L}\/\.。。・・︒។։။۔።。]|[.。。・・︒។։။۔።।](?!\p{L})))/u
var regex = RegExp(r"""(?:(?:(?<=\bwhat3words\.com/)|(?<=\bw3w\.co/))|(?<![^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s/.。。・・︒។։။۔።।]))(?:/{0,3})((?:(?:[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+(?:[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+){2})|(?:[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+(?:[\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+){1,3}(?:[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+(?:[\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+){1,3}){2})))(?![/.。。・・︒។։။۔።।]|[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s])""");
N/A: Rust doesn't support look-ahead and look-behind.
N/A: Go doesn't support look-ahead and look-behind.
wstring regex = L"\\b((?:(?:[^0-9`~!@#$%^&*()+\\-_=\\]\\[{\\}\\\\|'<,.>?/\";:£§º©®\\s]+(?:[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\\-_=\\]\\[{\\}\\\\|'<,.>?/\";:£§º©®\\s]+){2})|(?:[^0-9`~!@#$%^&*()+\\-_=\\]\\[{\\}\\\\|'<,.>?/\";:£§º©®\\s]+(?:[\\u0020\\u00A0][^0-9`~!@#$%^&*()+\\-_=\\]\\[{\\}\\\\|'<,.>?/\";:£§º©®\\s]+){1,3}(?:[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\\-_=\\]\\[{\\}\\\\|'<,.>?/\";:£§º©®\\s]+(?:[\\u0020\\u00A0][^0-9`~!@#$%^&*()+\\-_=\\]\\[{\\}\\\\|'<,.>?/\";:£§º©®\\s]+){1,3}){2})))(?![/])\\b";
var regex = /^\/{0,}(?:[\p{L}\p{M}]+[.。。・・︒។։။۔።।][\p{L}\p{M}]+[.。。・・︒។։။۔።।][\p{L}\p{M}]+|[\p{L}\p{M}]+([\u0020\u00A0][\p{L}\p{M}]+){1,3}[.。。・・︒។։။۔።।][\p{L}\p{M}]+([\u0020\u00A0][\p{L}\p{M}]+){1,3}[.。。・・︒។։။۔።।][\p{L}\p{M}]+([\u0020\u00A0][\p{L}\p{M}]+){1,3})$/gu;
String regex_string = "^/*(?:(?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+|(?:\\p{L}\\p{M}*)+([\u0020\u00A0](?:\\p{L}\\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+([\u0020\u00A0](?:\\p{L}\\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+([\u0020\u00A0](?:\\p{L}\\p{M}*)+){1,3})$";
regex_match = r"^/*(?:[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/\";:£§º©®\s]{1,}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/\";:£§º©®\s]+[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/\";:£§º©®\s]+|[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/\";:£§º©®\s]+([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/\";:£§º©®\s]+){1,3}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/\";:£§º©®\s]+([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/\";:£§º©®\s]+){1,3}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/\";:£§º©®\s]+([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/\";:£§º©®\s]+){1,3})$"
regex_string = "^/*(?:[\\p{L}\\p{M}]+[.。。・・︒។։။۔።।][\\p{L}\\p{M}]+[.。。・・︒។։။۔።।][\\p{L}\\p{M}]+|[\\p{L}\\p{M}]+([\u{20}\u{A0}][\\p{L}\\p{M}]+){1,3}[.。。・・︒។։။۔።।][\\p{L}\\p{M}]+([\u{20}\u{A0}][\\p{L}\\p{M}]+){1,3}[.。。・・︒។։။۔።।][\\p{L}\\p{M}]+([\u{20}\u{A0}][\\p{L}\\p{M}]+){1,3})$"
NSString *regex_string = @"^/*(?:[\\p{L}\\p{M}]+[.。。・・︒។։။۔።।][\\p{L}\\p{M}]+[.。。・・︒។։။۔።।][\\p{L}\\p{M}]+|[\\p{L}\\p{M}]+([ \u00A0][\\p{L}\\p{M}]+){1,3}[.。。・・︒។։။۔።।][\\p{L}\\p{M}]+([ \u00A0][\\p{L}\\p{M}]+){1,3}[.。。・・︒។։။۔።।][\\p{L}\\p{M}]+([ \u00A0][\\p{L}\\p{M}]+){1,3})$";
$regex_match = "/^\/*((?:\p{L}\p{M}*){1,}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*){1,}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*){1,}|\/*((?:\p{L}\p{M}*){1,}([\u{0020}\u{00A0}](?:\p{L}\p{M}*){1,}){1,3})[.。。・・︒។։။۔።।]((?:\p{L}\p{M}*){1,}([\u{0020}\u{00A0}](?:\p{L}\p{M}*){1,}){1,3})[.。。・・︒។։။۔።।]((?:\p{L}\p{M}*){1,}([\u{0020}\u{00A0}](?:\p{L}\p{M}*){1,}){1,3}))$/u";
var regexExact = new Regex("^/*(?:(?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+|(?:\\p{L}\\p{M}*)+([\u0020\u00A0](?:\\p{L}\\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+([\u0020\u00A0](?:\\p{L}\\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\\p{L}\\p{M}*)+([\u0020\u00A0](?:\\p{L}\\p{M}*)+){1,3})$");
regex_match = /^\/*(?:(?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+|(?:\p{L}\p{M}*)+(?:[ \u{00A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[ \u{00A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[ \u{00A0}](?:\p{L}\p{M}*)+){1,3})$/
var regexExact = RegExp(r"^\/{0,}(?:[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?\/"'"'r";:£§º©®\s]{1,}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?\/"'"'r";:£§º©®\s]{1,}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?\/"'"'r";:£§º©®\s]{1,}|[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?\/"'"'r";:£§º©®\s]{1,}([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?\/"'"'r";:£§º©®\s]+){1,3}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?\/"'"'r";:£§º©®\s]{1,}([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?\/"'"'r";:£§º©®\s]+){1,3}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?\/"'"'r";:£§º©®\s]{1,}([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?\/"'"'r";:£§º©®\s]+){1,3})$");
let regex_match = r#"^\/*(?:(?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+|(?:\p{L}\p{M}*)+(?:[ \u{00A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[ \u{00A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[ \u{00A0}](?:\p{L}\p{M}*)+){1,3})$"#;
regexMatch := `^\/*(?:(?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+|(?:\p{L}\p{M}*)+(?:[ \x{00A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[ \x{00A0}](?:\p{L}\p{M}*)+){1,3}[.。。・・︒។։။۔።।](?:\p{L}\p{M}*)+(?:[ \x{00A0}](?:\p{L}\p{M}*)+){1,3})$`
wstring regex_match = L"(^/*(?:[^0-9`~!@#$%^&*()+\\-_=\\]\\[{\\}\\\\|'<,.>?/\";:£§º©®\\s]{1,}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\\-_=\\]\\[{\\}\\\\|'<,.>?/\";:£§º©®\\s]{1,}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\\-_=\\]\\[{\\}\\\\|'<,.>?/\";:£§º©®\\s]{1,}|[^0-9`~!@#$%^&*()+\\-_=\\]\\[{\\}\\\\|'<,.>?/\";:£§º©®\\s]{1,}([\u0020\u00A0][^0-9`~!@#$%^&*()+\\-_=[{\\]}\\\\|'<,.>?/\";:£§º©®\\s]+){1,3}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\\-_=\\]\\[{\\}\\\\|'<,.>?/\";:£§º©®\\s]{1,}([\u0020\u00A0][^0-9`~!@#$%^&*()+\\-_=[{\\]}\\\\|'<,.>?/\";:£§º©®\\s]+){1,3}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\\-_=\\]\\[{\\}\\\\|'<,.>?/\";:£§º©®\\s]{1,}([\u0020\u00A0][^0-9`~!@#$%^&*()+\\-_=[{\\]}\\\\|'<,.>?/\";:£§º©®\\s]+){1,3})$)";
Overview
Our API wrapper RegEx function “isPossible3wa” (“is_possible_3wa” for Python & Rust API wrapper) can be used to detect if a text string (like “filled.count.soap“) in the format of a what3words address without having to ask the API. This functionality checks if a given string could be a what3words address. It returns true if it could be, otherwise false.
Benefits
- Quick Validation: Rapidly determine if a string resembles a what3words address.
- Error Prevention: Helps avoid errors by flagging potential what3words addresses for further validation.
import { AutosuggestClient } from "@what3words/api"; // Initialise the What3Words API with your API key const API_KEY = 'YOUR_API_KEY'; const client = AutosuggestClient.init(API_KEY); // Example what3words addresses const addresses = ["filled.count.soap", "not a 3wa", "not.3wa address"]; // Function to check if the address is a possible what3words address const checkPossible3wa = (address) => { const isPossible = client.isPossible3wa(address); console.log(`Is '${address}' a possible what3words address? ${isPossible}`); }; // Check each address addresses.forEach(checkPossible3wa);
public class What3WordsExample { public static void main(String[] args) { // Example what3words addresses String[] addresses = {"filled.count.soap", "not a 3wa", "not.3wa address"}; // Check if the addresses are possible what3words addresses for (String address : addresses) { boolean isPossible = What3WordsV3.isPossible3wa(address); System.out.println("Is '" + address + "' a possible what3words address? " + isPossible); } } }
import what3words def main(): # Initialize the What3Words API with your API key api_key = 'YOUR_API_KEY' w3w = what3words.Geocoder(api_key) # Example what3words addresses addresses = ["filled.count.soap", "not a 3wa", "not.3wa address"] # Check if the addresses are possible what3words addresses for address in addresses: is_possible = w3w.is_possible_3wa(address) print(f"Is '{address}' a possible what3words address? {is_possible}") if __name__ == "__main__": main()
import W3WSwiftApi import CoreLocation func main() { // Initialize the What3Words API with your API key let api = What3WordsV4(apiKey: "YOUR_API_KEY") // Example what3words addresses let addresses = ["filled.count.soap", "not a 3wa", "not.3wa address"] // Check if the addresses are possible what3words addresses for address in addresses { let isPossible = api.isPossible3wa(text: address) print("Is '\(address)' a possible what3words address? \(isPossible)") } } main()
<?php require_once("vendor/autoload.php"); use What3words\Geocoder\Geocoder; function main() { // Initialize the What3Words API with your API key $api = 'YOUR_API_KEY'; $w3w = new Geocoder($api); // Example what3words addresses $addresses = ["filled.count.soap", "not a 3wa", "not.3wa address"]; // Check if the addresses are possible what3words addresses foreach ($addresses as $address) { $isPossible = $w3w->isPossible3wa($address); echo "Is '{$address}' a possible what3words address? " . ($isPossible ? "true" : "false") . "\n"; } } main(); ?>
using System; using what3words.dotnet.wrapper; namespace What3WordsExample { class Program { static void Main(string[] args) { // Initialize the What3Words API with your API key var api = new What3WordsV3("YOUR_API_KEY"); // Example what3words addresses string[] addresses = { "filled.count.soap", "not a 3wa", "not.3wa address" }; // Check if the addresses are possible what3words addresses foreach (var address in addresses) { bool isPossible = api.IsPossible3wa(address); Console.WriteLine($"Is '{address}' a possible what3words address? {isPossible}"); } } } }
require 'what3words' def main # Initialize the What3Words API with your API key api_key = 'YOUR_API_KEY' w3w = What3Words::API.new(:key => api_key) # Example what3words addresses addresses = ["filled.count.soap", "not a 3wa", "not.3wa address"] # Check if the addresses are possible what3words addresses addresses.each do |address| is_possible = w3w.isPossible3wa(address) puts "Is '#{address}' a possible what3words address? #{is_possible}" end end if __FILE__ == $0 main end
void main() async { // Replace 'what3words-api-key' with your actual API key var api = What3WordsV3('what3words-api-key'); List<String> addresses = ["filled.count.soap", "not a 3wa", "not.3wa address"]; // Check if the addresses are possible what3words addresses for (String address in addresses) { bool isPossible = api.isPossible3wa(address); print("Is '$address' a possible what3words address? $isPossible"); } }
use what3words_api::What3words; fn main() { // Initialize the what3words API with your API key let api_key = "YOUR_API_KEY_HERE"; let w3w = What3words::new(api_key); // Example what3words addresses let addresses = [ "filled.count.soap", "not a 3wa", "not.3wa address", ]; // Check if the addresses are possible what3words addresses for address in &addresses { let is_possible = w3w.is_possible_3wa(address); println!("Is '{}' a possible what3words address? {}", address, is_possible); } }
package main import ( "fmt" w3w "github.com/what3words/w3w-go-wrapper" ) func main() { // Initialize the What3Words API with your API key apiKey := "<YOUR_API_KEY>" service := w3w.NewService(apiKey) // Example what3words addresses addresses := []string{"filled.count.soap", "not a 3wa", "not.3wa address"} // Check if the addresses are possible what3words addresses for _, address := range addresses { isPossible := service.IsPossible3wa(address) fmt.Printf("Is '%s' a possible what3words address? %t\n", address, isPossible) } }
Expected Output
- isPossible3wa(“filled.count.soap”) returns
true - isPossible3wa(“not a 3wa”) returns
false - isPossible3wa(“not.3wa address”) returns
false
Steps
- Initialise the API with your What3Words API key. [Note: Not applicable for Java wrapper]
- Check if each address is a possible what3words address using
isPossible3wa. - Print the result for each address.
Dependencies
Ensure you have the necessary dependencies installed for the what3words API Wrapper that you have chosen. For more information, refer to our what3words API Wrappers.
Overview
Our API wrapper RegEx function “isValid3wa” (“is_valid_3wa” for our Python & Rust API wrapper) can be used to determine if a string is a valid what3words address by checking it against the what3words regex filter and verifying it with the what3words API.
Benefits
- Reliable Validation: Ensure the accuracy of what3words addresses by confirming their existence.
- Integration with What3Words API: Seamlessly integrate address verification with the what3words API.
import { AutosuggestClient } from "@what3words/api"; const API_KEY = 'YOUR_API_KEY'; const client = AutosuggestClient.init(API_KEY); // Example addresses const addresses = [ "filled.count.soap", "filled.count.", "coding.is.cool" ]; // Function to check if the address is valid const checkIsValid3wa = async (address) => { try { const isValid = await client.isValid3wa(address); console.log(`Is '${address}' a valid what3words address? ${isValid}`); } catch (error) { console.error(`Error validating address '${address}':`, error); } }; // Check each address for validity addresses.forEach(checkIsValid3wa);
public class What3WordsExample { public static void main(String[] args) { // Initialize the What3Words API with your API key What3WordsV3 api = new What3WordsV3("YOUR_API_KEY"); // Example addresses String[] addresses = { "filled.count.soap", "filled.count.", "coding.is.cool" }; // Check if the addresses are valid what3words addresses for (String address : addresses) { boolean response = api.isValid3wa(address); if (response.isSuccessful() && response.getIsValid()) { System.out.println(address + " is a valid what3words address"); } else if (response.isSuccessful() && !response.getIsValid()) { System.out.println(address + " is an invalid what3words address"); } else { System.out.println("isValid3wa error: " + response.getError().getKey() + " " + response.getError().getMessage()); } } } }
import what3words def main(): # Initialize the what3words API with your API key api_key = 'YOUR_API_KEY' w3w = what3words.Geocoder(api_key) # Example addresses addresses = [ "filled.count.soap", "filled.count.", "coding.is.cool" ] # Check if the addresses are valid what3words addresses for address in addresses: is_valid = w3w.is_valid_3wa(address) print(f"Is '{address}' a valid what3words address? {is_valid}") if __name__ == "__main__": main()
import W3WSwiftApi import CoreLocation func main() { // Initialize the what3words API with your API key let apiKey = "YOUR_API_KEY" let api = What3WordsV4(apiKey: apiKey) // Example addresses let addresses = [ "filled.count.soap", "filled.count.", "coding.is.cool" ] // Check if the addresses are valid what3words addresses for address in addresses { api.isValid3wa(words: address) { result in if result == true { print("'\(address)' is a valid what3words address") } else { print("'\(address)' is NOT a valid what3words address") } } } } main()
<?php require_once("vendor/autoload.php"); use What3words\Geocoder\Geocoder; function main() { // Initialize the what3words API with your API key $apiKey = 'YOUR_API_KEY'; $w3w = new Geocoder($apiKey); // Example addresses $addresses = [ "filled.count.soap", "filled.count.", "coding.is.cool" ]; // Check if the addresses are valid what3words addresses foreach ($addresses as $address) { $isValid = $w3w->isValid3wa($address); echo "Is '$address' a valid what3words address? " . ($isValid ? 'True' : 'False') . "\n"; } } main();
using System; using what3words.dotnet.wrapper; namespace What3WordsExample class Program { static void Main(string[] args) { // Initialize the what3words API with your API key var api = new What3WordsV3("YOUR_API_KEY"); // Example addresses string[] addresses = { "filled.count.soap", "filled.count.", "coding.is.cool" }; // Check if the addresses are valid what3words addresses foreach (var address in addresses) { bool isValid = api.IsValid3wa(address); Console.WriteLine($"Is '{address}' a valid what3words address? {isValid}"); } } }
require 'what3words' def main # Initialize the what3words API with your API key api_key = 'YOUR_API_KEY' w3w = What3Words::API.new(:key => api_key) # Example addresses addresses = [ "filled.count.soap", "filled.count.", "coding.is.cool" ] # Check if the addresses are valid what3words addresses addresses.each do |address| is_valid = w3w.isValid3wa(address) puts "Is '#{address}' a valid what3words address? #{is_valid}" end end if __FILE__ == $0 main end
void main() async { // Replace 'what3words-api-key' with your actual API key var api = What3WordsV3('what3words-api-key'); List<String> w3w_addresses = [ "filled.count.soap", "filled.count.", "coding.is.cool" ]; // Iterate over the list and check if each address is valid for (String w3w_address in w3w_addresses) { var response = await api.isValid3wa(w3w_address); if (response.isSuccessful() && response.isValid == true) { print("$w3w_address is a valid what3words address"); } else if (response.isSuccessful() && response.isValid == false) { print("$w3w_address is an invalid what3words address"); } else { print("isValid3wa error: ${response.error?.code} - ${response.error?.message}"); } } }
use what3words_api::What3words; fn main() { // Initialize the what3words API with your API key let api_key = "YOUR_API_KEY_HERE"; let w3w = What3words::new(api_key); // Example addresses let addresses = vec![ "filled.count.soap", "filled.count.", "coding.is.cool", ]; // Check if each address is a valid what3words address for address in addresses { let is_valid = w3w.is_valid_3wa(address); println!("Is '{}' a valid what3words address? {}", address, is_valid); } }
package main import ( "context" "fmt" w3w "github.com/what3words/w3w-go-wrapper" ) func main() { // Initialize the What3Words API with your API key apiKey := "<YOUR_API_KEY>" service := w3w.NewService(apiKey) // Example addresses addresses := []string{ "filled.count.soap", "filled.count.", "coding.is.cool", } // Check if the addresses are valid what3words addresses for _, address := range addresses { isValid, err := service.IsValid3wa(context.Background(), address) if err != nil { fmt.Printf("Error validating address '%s': %v\n", address, err) } else { fmt.Printf("Is '%s' a valid what3words address? %t\n", address, isValid) } } }
Expected Outputs
- isValid3wa(“filled.count.soap”) returns
True - isValid3wa(“filled.count.”) returns
False - isValid3wa(“coding.is.cool”) returns
False
Steps
- Initialise the API with your What3Words API key.
- Define example addresses to validate.
- Use the
isValid3wafunction to check if each address is valid. - Print the validation results for each address.
Dependencies
Ensure you have the necessary dependencies installed for the what3words API Wrapper that you have chosen. For more information, refer to our what3words API Wrappers.
Have any questions?
We’re here to support you! If you have any questions while using our what3words Regex expressions, get in touch with us by writing us an email at support@what3words.com.