Text Filters - REGEX


Functionality

The text filters feature allows you to specify content that should be masked by the system. This can be used to better manage content that may be inappropriate or otherwise not allowed on your marketplace. For instance, you can filter out all email addresses posted in listing descriptions, so as to reduce the chances that your users will encourage others to contact them directly by going around your marketplace (thus not needing to pay the service fee!).

Text filters can be created for filtering out just about any string - emails, phone numbers, addresses, etc. Importantly, for content that should be filtered you will need to specify the REGEX ( Regular Expression), which is what our system uses to find the string that needs to be masked. Below, we have included the common regular expressions that people use to mask content on their marketplace, but you are not restricted to using only what we have provided.


Location

Admin Dash > Settings > Configuration > Text Filters


How To Create a New Text Filter

  1. Turn on the text filtering system by checking the box labeled Apply Text Filters

  2. You can add as many new text filters as you would like, by clicking on the add text filter button, or delete text filters by selecting the trash can icon

  3. Enter a name - this can be anything you want and is only used to help you keep track of which filters you have created

  4. Enter the regular expression corresponding to the content you would like to filter

  5. Enter the replacement text - this is the text that will replace the content you would like to filter, and can be anything you want (e.g. *****, [MASKED], [REMOVED], etc.)

  6. Be sure to check the 'Ignore Case' box if you would like the text filter to catch all wanted phrases regardless of case.
  7. Scroll to the bottom of the page and click save

  8. The final step is to make sure that your liquid markup has been amended to allow the text filters to function. We do this by adding a bit of markup to the end of the liquid tag (see an example in the image below). In our example we are adding the text filter to  {{ listing.properties.summary_of_listing }}, so we will add the markup  | filter_text | custom_sanitize to it, with the result being:  {{ listing.properties.summary_of_listing | filter_text | custom_sanitize }}


Additional Notes

Here is a website that will allow you to build/test your expressions:   http://regexr.com/

Here are some common regular expressions:

  • Emails: [A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}
  • 7 digit phone number: (?:\(?([0-9]{3})\)?[-. ]?)?([0-9]{3})[-. ]?([0-9]{4})
  • 10 digit phone number: \(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})
  • Phone number with leading 1: (?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})
  • Generic Simple Phone:  \d[-\d()\s.]{5,}\d
  • URL's: (http\:\/\/|https\:\/\/)?([a-z0-9][a-z0-9\-]*\.)+[a-z0-9][a-z0-9][a-z0-9]
  • Phone Number spelled out: \b(?:(?:one|two|three|four|five|six|seven|eight|nine|zero)\b\s*?){10}
  • Facebook: (facebook)