All Collections
Editor Questions
How-To Questions
How to use fields Modifier, Format, and Separator? (helpers for Smart- elements)
How to use fields Modifier, Format, and Separator? (helpers for Smart- elements)

In this article, you'll learn how to work with fields Modifier, Format, and Separator (helpers for Smart- elements).

Oleksandr avatar
Written by Oleksandr
Updated over a week ago

Let's consider how we can modify or format pulled data (cut out some part of it, change, add any extra text, or for example, you'd like to round, group, or add symbols to the price).

Modifier and Replacement fields.

First, I'm going to familiarize you with the fields Modifier and Replacement.

In order to leave a certain length of text, we can use Modifier – (.{0,*})(.{0,}) where the star means how many symbols will remain (including spaces and any symbols) with

Replacement – $1

To add some text before, after, or around the pulled data, we can use

Modifier – (^(.*)$)

Replacement – any_text_before $1 any_text_after

Possible to use one modifier or more together

The Modifier field is (.{0,20})(.{0,}) and the Replacement field is $1  - outputed result is Samsung Galaxy Note1
The Modifier field is (^(.*)$) and the Replacement field is y_txt $1 y_txt - outputed result is y_txt Samsung Galaxy Note1 y_txt

To add the missing protocol to the link, we can use

Modifier – ^// (if text starts with "//").

Replacement – https://

To change the path in a link, for example, if the image link starts with /image/

then we replace /image/ with http://rockway.biz/image/

Modifier – /image/

For the next two examples, I'm going to use the price with the US Dollar sign

US $379.05

This is how it looks, pulled from a website, as it is.

We can change one symbol with another, for example, the dollar sign with the cent sign.

Draw your attention, that the dollar sign is already occupied for special regexp symbols, so it must be shielded with the backslash.

The Modifier field is \$ and the Replacement field is ¢  - outputed result is US ¢379.05

Also, we can cut out the US $ part from the start (first modifier) and add the NZ $ to the end (second modifier)

The Modifier field is (^\w+\$) and the Replacement field is empty - outputed result is 379.05
The Modifier field is $ and the Replacement field is NZ \$ - outputed result is 379.05 NZ $

If you didn't familiar with regular expressions at this moment, I recommend you to use this resource to read about and this one to try and test it in a practice way.

Format and Separator fields.

Let's consider one more useful option and try to round, group, or add some symbols to our data.

The fields Format and Separator give us such a possibility.

By the way, these fields work only with data consisting of numbers with no spaces (actually, that is why we've considered the Modifier field firstly)

First, we'll try to leave only 379.05 and delete the US $ to prepare our data for further use.

For this, we can use the Modifier field with the (\d+\.\d+) expression, based on a standard regular expressions template.

The Modifier field is (\d+\.\d+) - outputed result is 379.05

There are 11 Special Pattern Characters, but we'll cover the most important ones:

  • 0 – prints a digit if provided, 0 otherwise

  • # – prints a digit if provided, nothing otherwise

  • . – indicate where to put the decimal separator

  • , – indicate where to put the grouping separator

In the following examples, we will see how this works on a number 379.05

Simple Decimals

The Format field is ####.### - outputed result is 379.05
The Format field is 0000.000 - outputed result is 0379.050

If the pattern is bigger than the number, zeros get added, while hashes get dropped, both in the integer and in the decimal parts.

Rounding

If the decimal part of the pattern can't contain the whole precision of the input number, it gets rounded.

Here, the .05 part has been rounded to .10, and then the 0 has been dropped:

The Format field is #.# - outputed result is 379.1

Here, the .05 part has been rounded to 0.00, then the .00 has been dropped and the 379 has stayed as it was:

The Format field is # - outputed result is 379

Grouping

The grouping separator is used to specify a sub-pattern which gets repeated automatically:

Draw your attention to the fact that the Separator will be set as a dot by default, and after it has been set once after the first three symbols - it will be repeated after every three characters in a result.

The Format field is 0000,000.## and the Separator field is empty - outputed result is 0.000.379.05
All the extra zeros in left were added only to show how the separator will be displayed with biger numbers.

Also, you can set any symbol as the Separator (in my example, I've used the dash)

The Format field is 0000,00 and the Separator field is dash - outputed result is 00-03-79

Mixing String Literals

It's possible to mix String literals within the pattern:

The Format field is "The # number" - outputed result is "The 379 number"

It's also possible to use special characters as String literals through escaping:

The Format field is "The '#' #th" - outputed result is "The # 379th"

And of course, we can combine all considered options in one formatting template ;)



Thank you for taking the time to read our articles. We hope you will find this information helpful.


If you have any additional questions, please email us at support@stripo.email.

We would be glad to talk with you.


Did this answer your question?