Get specific data from a string

Something simple that I can figure out how to do or isn’t possible. I have the read email node it returns data, but I want to extract the data I need not having to use the whole string, because I want to update a google sheet with the info but the string contains general info I don’t need

example

I don’t want the whole text just the NINE which changes on new execution. so pretty much just the part that changes the ticker and I don’t have any coding experience beyond able to figure things out, but this is a necessary node if it doesn’t exist

Hi, you can accomplish this with a combination of the SET node and the use of a regular expression (regex). I put together one that should work for your use case, paste this into a new workflow, connect it to the start node, then hit execute. You can then see how the regex value works within the Set node to give you the number nine:

{
  "nodes": [
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "TICKER",
              "value": "TradingView Screener Alert:\nNew Tickers:\nNYSE:NINE"
            }
          ]
        },
        "options": {}
      },
      "name": "Get initial values",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "If the value always contains NYSE: ",
              "value": "={{$json[\"TICKER\"].match(/(?<!\\w)\\w+$/).toString()}}"
            }
          ]
        },
        "options": {}
      },
      "name": "NYSE",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    }
  ],
  "connections": {
    "Get initial values": {
      "main": [
        [
          {
            "node": "NYSE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

I couldnt get it to work heres a copy of my work flow the NINE is the part that changes to randon tickers APPL TSLA etc in the end I just want the ticket by itself to be added to a cell in google sheets

{
“nodes”: [
{
“parameters”: {
“keepOnlySet”: true,
“values”: {
“string”: [
{
“name”: “TICKER”,
“value”: “={{$json[“raw”]}}”
}
]
},
“options”: {
“dotNotation”: false
}
},
“name”: “Set”,
“type”: “n8n-nodes-base.set”,
“typeVersion”: 1,
“position”: [
400,
200
]
},
{
“parameters”: {
“postProcessAction”: “nothing”,
“format”: “raw”,
“options”: {
“customEmailConfig”: “[“UNSEEN”]”,
“allowUnauthorizedCerts”: true
}
},
“name”: “IMAP Email”,
“type”: “n8n-nodes-base.emailReadImap”,
“typeVersion”: 1,
“position”: [
0,
200
],
“credentials”: {
“imap”: {
“id”: “15”,
“name”: “IMAP account”
}
}
},
{
“parameters”: {
“operation”: “removeDuplicates”
},
“name”: “Item Lists”,
“type”: “n8n-nodes-base.itemLists”,
“typeVersion”: 1,
“position”: [
220,
200
]
},
{
“parameters”: {
“values”: {
“string”: [
{
“name”: “TICKER”,
“value”: “TradingView Screener Alert:\nNew Tickers:\nNYSE:NINE”
}
]
},
“options”: {}
},
“name”: “Get initial values”,
“type”: “n8n-nodes-base.set”,
“typeVersion”: 1,
“position”: [
480,
20
]
},
{
“parameters”: {
“values”: {
“string”: [
{
“name”: "If the value always contains NYSE: ",
“value”: “={{$json[“TICKER”].match(/(?<!\w)\w+$/).toString()}}”
}
]
},
“options”: {}
},
“name”: “NYSE”,
“type”: “n8n-nodes-base.set”,
“typeVersion”: 1,
“position”: [
700,
20
]
}
],
“connections”: {
“IMAP Email”: {
“main”: [
[
{
“node”: “Item Lists”,
“type”: “main”,
“index”: 0
}
]
]
},
“Item Lists”: {
“main”: [
[
{
“node”: “Set”,
“type”: “main”,
“index”: 0
}
]
]
},
“Get initial values”: {
“main”: [
[
{
“node”: “NYSE”,
“type”: “main”,
“index”: 0
}
]
]
}
}
}

It won’t let me copy this into my n8n instance, you need to make sure you use the </> icon in your forum post when pasting in code so I can copy it correctly. If you don’t do that, it introduces weird spaces which means I can’t paste it into my viewer.

It would also help to see a screenshot of the google sheet, or the layout that you are using in the sheet.

ok I see let me do that now thank you

I have this spreadsheet and formulas that I use and I want to replace the ticker symbol with symbol I pull for email

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "sheetId": "1kzeIiYSf4xTsrB06m88RoHVj4QrUAc1UICDCRscU8ps",
        "range": "M:R",
        "options": {}
      },
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1020,
        100
      ],
      "credentials": {
        "googleApi": {
          "id": "8",
          "name": "Google account"
        }
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "TICKER",
              "value": "={{$json[\"raw\"]}}"
            }
          ]
        },
        "options": {
          "dotNotation": false
        }
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        400,
        200
      ]
    },
    {
      "parameters": {
        "postProcessAction": "nothing",
        "format": "raw",
        "options": {
          "customEmailConfig": "[\"UNSEEN\"]",
          "allowUnauthorizedCerts": true
        }
      },
      "name": "IMAP Email",
      "type": "n8n-nodes-base.emailReadImap",
      "typeVersion": 1,
      "position": [
        0,
        200
      ],
      "credentials": {
        "imap": {
          "id": "15",
          "name": "IMAP account"
        }
      }
    },
    {
      "parameters": {
        "operation": "removeDuplicates"
      },
      "name": "Item Lists",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        220,
        200
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "TICKER",
              "value": "TradingView Screener Alert:\nNew Tickers:\nNYSE:NINE"
            }
          ]
        },
        "options": {}
      },
      "name": "Get initial values",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        480,
        20
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "If the value always contains NYSE: ",
              "value": "={{$json[\"TICKER\"].match(/(?<!\\w)\\w+$/).toString()}}"
            }
          ]
        },
        "options": {}
      },
      "name": "NYSE",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        700,
        20
      ]
    }
  ],
  "connections": {
    "IMAP Email": {
      "main": [
        [
          {
            "node": "Item Lists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Item Lists": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get initial values": {
      "main": [
        [
          {
            "node": "NYSE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Ok try this:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "postProcessAction": "nothing",
        "format": "raw",
        "options": {
          "customEmailConfig": "[\"UNSEEN\"]",
          "allowUnauthorizedCerts": true
        }
      },
      "name": "IMAP Email",
      "type": "n8n-nodes-base.emailReadImap",
      "typeVersion": 1,
      "position": [
        440,
        440
      ],
      "credentials": {
        "imap": {
          "id": "15",
          "name": "IMAP account"
        }
      }
    },
    {
      "parameters": {
        "operation": "removeDuplicates"
      },
      "name": "Item Lists",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        660,
        440
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "sheetId": "1kzeIiYSf4xTsrB06m88RoHVj4QrUAc1UICDCRscU8ps",
        "range": "M:R",
        "options": {}
      },
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1020,
        440
      ],
      "credentials": {
        "googleApi": {
          "id": "8",
          "name": "Google account"
        }
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "Symbol",
              "value": "={{$json[\"raw\"].match(/(?<!\\w)\\w+$/).toString()}}"
            }
          ]
        },
        "options": {
          "dotNotation": false
        }
      },
      "name": "Set values to pass into Sheets",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        840,
        440
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Item Lists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IMAP Email": {
      "main": [
        [
          {
            "node": "Item Lists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Item Lists": {
      "main": [
        [
          {
            "node": "Set values to pass into Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set values to pass into Sheets": {
      "main": [
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Doesn’t work returns nothing, is there a way to remove matching text from a previous node like if the previous data was 123456 and I say any data that matches 12345 then remove, then im left with 6 as final output. here is screenshot of errors and output.




Hi, sorry I am unable to test since I’m not using the imap node. I used the set node to recreate the outputs from your imap and it’s working for me here:

{
  "nodes": [
    {
      "parameters": {
        "operation": "removeDuplicates"
      },
      "name": "Item Lists",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        620,
        440
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "Symbol",
              "value": "={{$json[\"raw\"].match(/(?<!\\w)\\w+$/).toString()}}"
            }
          ]
        },
        "options": {
          "dotNotation": false
        }
      },
      "name": "Set values to pass into Sheets",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        960,
        440
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "raw",
              "value": "TradingView Screener Alert: New Tickers: NYSE:NINE"
            }
          ]
        },
        "options": {}
      },
      "name": "recreate imap values",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        800,
        440
      ]
    }
  ],
  "connections": {
    "Item Lists": {
      "main": [
        [
          {
            "node": "recreate imap values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "recreate imap values": {
      "main": [
        [
          {
            "node": "Set values to pass into Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

It still doesn’t work but I think I know what the issue is the result comes with a space at the end I had a issue with anothr work flow with space being the issue

Would you mind pasting the values it’s outputting here? I can try again and see if it’s the regex or something else.

At the end of the ticket theres a small space when I replicate in your flow the space it fail producing just the brackets but when I remove the space it works like intended it would be prefect if it could just return only the part I need “ticker” without space for the IMAP output like SERA only

[
{
"TICKER": " TradingView Screener Alert: New tickers: NASDAQ:SERA "
},
{
"TICKER": " TradingView Screener Alert: New tickers: NASDAQ:DAVE "
},
{
"TICKER": " TradingView Screener Alert: New tickers: NASDAQ:ONCS "
},
{
"TICKER": " TradingView Screener Alert: New tickers: NASDAQ:MDVL, NASDAQ:SERA "
},
{
"TICKER": " TradingView Screener Alert: New tickers: NASDAQ:BBBY "
},
{
"TICKER": " TradingView Screener Alert: New tickers: NASDAQ:BBBY, NASDAQ:SERA "
},
{
"TICKER": " TradingView Screener Alert: New tickers: NASDAQ:GMVD "
},
{
"TICKER": " TradingView Screener Alert: New tickers: NASDAQ:GMVD, NASDAQ:SERA "
},
{
"TICKER": " TradingView Screener Alert: New tickers: NASDAQ:UK "
},
{
"TICKER": " TradingView Screener Alert: New tickers: NASDAQ:KRMD "
},
{
"TICKER": " TradingView Screener Alert: New tickers: NASDAQ:MBII "
}
]

Ahhh Ok I see the issue, let me play with this for a bit.

Ok I think I got it. You should be able to remove the Mock data node and replace it with the Imap node:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        0,
        460
      ]
    },
    {
      "parameters": {
        "operation": "removeDuplicates"
      },
      "name": "Item Lists",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        360,
        460
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "sheetId": "1kzeIiYSf4xTsrB06m88RoHVj4QrUAc1UICDCRscU8ps",
        "range": "M:R",
        "options": {}
      },
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1060,
        560
      ],
      "credentials": {
        "googleApi": {
          "id": "8",
          "name": "Google account"
        }
      },
      "disabled": true
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "Symbol",
              "value": "={{$json[\"TICKER\"].match(/(?<=\\w:)\\w+/).toString()}}"
            }
          ]
        },
        "options": {
          "dotNotation": false
        }
      },
      "name": "Set values to pass into Sheets",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        880,
        560
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      id: 1,\n      TICKER: \" TradingView Screener Alert: New tickers: NASDAQ:SERA \"\n    }\n  },\n  {\n    json: {\n      id: 2,\n      TICKER: \" TradingView Screener Alert: New tickers: NASDAQ:DAVE \"\n    }\n  },\n  {\n    json: {\n      id: 3,\n      TICKER: \" TradingView Screener Alert: New tickers: NASDAQ:ONCS \"\n    }\n  }\n];"
      },
      "name": "Mock Data",
      "type": "n8n-nodes-base.function",
      "position": [
        160,
        460
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$node[\"Split In Batches of 1\"].context[\"noItemsLeft\"]}}",
              "value2": true
            }
          ]
        }
      },
      "name": "Check if any left to process",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1280,
        240
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "Split In Batches of 1",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        660,
        460
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Mock Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Item Lists": {
      "main": [
        [
          {
            "node": "Split In Batches of 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets1": {
      "main": [
        [
          {
            "node": "Check if any left to process",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set values to pass into Sheets": {
      "main": [
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mock Data": {
      "main": [
        [
          {
            "node": "Item Lists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if any left to process": {
      "main": [
        null,
        [
          {
            "node": "Split In Batches of 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split In Batches of 1": {
      "main": [
        [
          {
            "node": "Set values to pass into Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Works, thank you :partying_face:

1 Like

Glad to hear it :smile: Have fun!

1 Like