REGEX - New Line

Hi, anybody can help me with this ? I check VAT numbers calling an API that returns a JSON where in the “address field” there are special characters like \n that separate the address in two lines. This is an example of the raw data that I get from the API call:

“address”: “street and number \nzip code city state\n”

What I would like to achieve is to fill at least two diffeterent input elements on the page, like INPUT STREET ADDRESS and INPUT CITY STATE, so that user can then save to DB in the corresponding fields.

Doing some research I found that I have probably to use regular expression to do this, but have no idea how to do it. This is a test I am doing with a text element.

Are there any example that I can just copy and paste ?

Best it would be to separate also ZIP CODE from CITY and STATE, but I do not know if it’s possibile.

Thank you so much for your help

If the formatting is exactly as in the example you can try:

For street: (.*) \\n
For zip/state: \\n(.*)\\n

HI @simon7, I tried this for extracting the address (first line). Can you confirm that the syntax is right ? or maybe I should have changed the * with something else. Consider that I do not have a clue of what I am doing …

Schermata 2020-04-02 alle 13.37.49

Schermata 2020-04-02 alle 13.37.20

Schermata 2020-04-02 alle 13.28.25

Hi Stefano,

From the looks it seems that this could work instead:
first: (.*)\n
second: \n(.*)

Short explanation: We try to extract whatever is inside the ( ). Here we have a “dot” which means every character, and the * means zero-to-unlimited times. The \n works as a delimiter. In the first example we try to get whatever is before a newline character, and in the second we extract whatever comes after the newline character. If, for example you only wanted to extract numbers it could be written like (\d*)\n as “\d” means “any number” in regex-language :slight_smile:

Btw. after the regex add a “trimmed” to remove unintentional spaces.

If this doesnt work, is it possible for you to share the api? Regex can be stupidly hard to get right without the source. Otherwise you could share the raw result from api connector (api connector → initialize → show raw data).

Skærmbillede 2020-04-02 kl. 14.03.13
Skærmbillede 2020-04-02 kl. 14.03.38

Got api-key in private message, the solution is to use (.*)\n for both values, and then in the editor choose first item / last item respectively.

Thank you @simon7

This topic was automatically closed after 70 days. New replies are no longer allowed.