Change columns output using regular expression
Set regular expression
Regular expressions is a powerful tool which allow you to change the column results. For example, you can use them to:
Create a regular expression to remove unwanted prefixes, e.g. "Phone: ", "Price - " from the results
You can use in conjunction with the Output HTML option to get the raw HTML for the selected element and create a regular expression to extract the exact data that you want from the HTML code.
Standard regular expression syntax is supported. There are a number of excellent online regular expression tutorials that you can follow to learn more about the syntax. Since Import.io extractor uses native JavaScript regular expression functions, some regular expression features such as lookbehind are not supported. Check out this article for more details.
The examples below show two possible ways that regular expression can be used.
Example 1
Step 1. Identify the common expression you wish to remove
In the following example, you can see how to use the "Set regular expression" option to remove the "Mfr#: " prefix from the Manufacturer number values:
Step 2. Add in the command text which will enable you remove extra characters
(.+) if placed after characters will make regular expression look for character string with that previous characters and replace them. In this example we will thus use Mfr#:(.+)
Step 3. Set replace as $1
So we put Mfr#:(.+) in the first box, and then by using $1 in the second box we can remove all of the prefixes.
Example 2
Step 1. Select the data you want to transform
In the next example, we show you how to easily enrich your data transforming "£x-y" to something like "from x to y GBP":
Step 2. Set regular expression to transform data
Here, the expression £([0-9]*)-([0-9]*) looks for two numerical strings separated by "-". And inside Replace: $1 references the item inside first set of brackets (in the _Match _expression), while $2 references the item inside the 2nd set of brackets.
Thus transforming the data from £11-25 to 11-25 Gbp.