Split text inside a field

Hello again! I have a question about what node to use when I want to split a text inside a field.

for example:
textField > Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

what if i only want to get the last sentence of this text? how do i do this?

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

@reve , any node can be used. It depends on what you are going to do with that extracted value. You can apply the expression {{ $json["textField"].split('. ').slice(-1)[0] }} as in

Though, the solution relies on the sentences formatted properly in the first place. That is, it expects that each sentence ends with a dot (.) followed by a space (except the very last one, which ends with just a dot.)

1 Like

thank you, will try. i will convert the extracted value to json. :slight_smile:


i got it. but the word “forwarded message” still included. cause i am retrieving a data from a forwarded message in gmail

1 Like


@reve , it is hard to get it right because you work with unstructured data. There are always going to be edge cases you haven’t anticipated as different email clients can produce different result. If all the communications are done in GMail ecosystem, then you could try to handle it and adjusting as you go.

For example, to get rid of “---------- Forwarded message ---------”, you could apply .replace('---------- Forwarded message ---------', ''). That is, taken into account what you have now (assuming it does work for you and you just want to remove the “forwarded” string), the whole expression will be {{ $json["text"].split(':').slice(-1)[0].replace('---------- Forwarded message ---------', '') }}

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.