I'd recommend a /while loop with $istok(), but it should be possible to merge the two strings together and create a pattern that walks for matching tokens on both sides of the center line.

//var %s = f,o,x,e,s|p,i,x,e,l,s | echo -a $regex(%s,/(?<=^|,)([^|,]+)(?=(?:,.*?)?\|(?:.*?,)?\1(?:,|$))/g) - $regml(1) - $regml(2) - $regml(3) - $regml(4) - $regml(5)

> 3 - x - e - s - -

This might contain some bugs that I missed, but I think I caught them all.

Code
/(?<=^|,)([^|,]+)(?=(?:,.*?)?\|(?:.*?,)?\1(?:,|$))/g

/
  (?<=^|,)      // look-behind for either start-of-line or a comma.
  ([^|,]+)      // capture group: start reading characters that are neither pipe nor comma.
  (?=           // look-ahead: and these characters must be followed by all of this...
    (?:,.*?)?   //   optionally: a comma and more characters on the left side of the pipe
    \|          //   the center-line pipe must be there
    (?:.*?,)?   //   optionally: more characters followed by a comma
    \1          //   the matching capture group of characters from earlier
    (?:,|$)     //   must be followed by a comma or the end-of-line
  )             // end of look-ahead collection.
/g              // global:  do this over and over again to find multiple matches.


If I were to write this a little better, I would use the magical \G anchor at the beginning to assert that nothing gets skipped, but I already wrote it so.

Last edited by Raccoon; 23/04/21 12:19 PM.

Well. At least I won lunch.
Good philosophy, see good in bad, I like!