Regex to match surrounding fields and extract text between (Modify node)

Describe the problem/error/question

I have understood that you can match with regex specific data to extract surround info in the Modify node (with the mysterious grouping (?<! MATCH) with toString.
// Explanation on the grouping of match (?<! would be great. Any good references???

Anyway, an example:

Field “textblob” which contains “alotgarbage\nuser password:thesecretpassword\nmoregarbage”

I want to regex out “thesecretpassword” using regex (matching all potential characters,
between “\nuser password” and before the “\n” after the secret password.

The function needed to extract this to a new String value would be great.
:slight_smile:

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

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

@DkYSwe , here’s an example how that could be achived.

The solution assumes that the keyword “password:” is present as is. I did not use ?<! at all.

If you still interested to know what that is, here’s the document. It represents a search technique called “lookbehind” (there is also “lookahead”).

1 Like