All tutorials

Detecting if text is in the format of a 3 word address using RegEx

easy

RegEx can be used to detect if a text string (like “filled.count.soap”) looks like a 3 word address, without having to ask the API.

We provide two regular expressions: one for an exact match, used for determining if a given text sample is exactly in the form of a 3 word address, and the other is for searching for 3 word addresses in sentences or paragraphs. The difference is the begin and end characters in the RegEx.

Regular expressions are provided for JavaScript, Java, Python, Swift, Objective-C and PHP, .NET and Dart.

1

RegEx

These are the RegEx for detecting a full 3 word address. For example, “filled.count.soap”. The expressions are designed to work across all languages

var regex = /^\/{0,}(?:[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+[.。。・・︒។։။۔።।][^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})$/;
Copied
2

Code Sample

Now we add the RegEx to a code sample that defines the text, passes through the RegEx and then prints whether the text is a 3 word address.

Note for Python: Depending on the languages you are using you might explicitly set utf-8 encoding by calling reload(sys).setdefaultencoding("utf8") at the begining of your script, and placing # -*- coding: utf-8 -*- at the top of your file. Also, don’t forget to import re.

var text  = "index.home.raft";
var regex = /^\/{0,}(?:[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+[.。。・・︒។։။۔።।][^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})$/;

if (regex.test(text))
  print(text + " is the format of a three word address");
else
  print(text + " is NOT the format of a three word address");
Copied

Related tutorials