You are viewing limited content. For full access, please sign in.

Question

Question

multiline pattern match

asked on March 17, 2015

I am trying to pattern match a multiline field out of another multiline field.

 

For example 

Field 1

Line 1

Line 2

Line 3 

 

Field 2 

Line 1

Line 2

Line 3

Line 4 

Line 5

 

I want to end up with 

 

Line 4 

Line 5

 

I don't know how many lines each field will have ahead of time. 

I am lost when it comes to the multiple lines. 

 

0 0

Replies

replied on March 17, 2015

Are the values going to match exactly? As in value 1 in field 1 will match value 1 in field 2, value 2 in field 1 will match value 2 in field 2? Or could the order be different?

0 0
replied on March 17, 2015 Show version history

If you basically want to remove a sequence in one list from the other, like

List 1

Value 3

Value 4

Value 5

__and__

List 2

Value 1

Value 2

Value 3

Value 4

Value 5

Value 6

__becomes__

List 3

Value 1

Value 2

Value 6

 

And the sequence is expected to be contiguous, then I suppose you could use pattern matching by doing

1) Join all values by newline for each list via token editor "index"

2) Set the "input" on the pattern matching activity to be the joined value of list 2.

3) Set the "pattern" on the pattern matching activity to be the joined value of list 1 like this:

    ^(.*)%(Value_Of_List_1_Joined_By_Newlines)(.*)$

    and set it to return all results with no spaces

4) On the resulting token, use a token function to split by newline. This new value is your List 3 as a MV token.

 

This approach is probably how you'd do what you want with pattern matching but it runs into a couple of problems. 

1) Assumes the values are contiguous

2) Assumes the values have no special regex chars, which would cause issues here

3) It's kinda using the pattern matching activity a bit "outside its element".

 

I think a better approach would be to use the For Each Value activity paired with some conditional activities and an Assign Token Value activity... but their usage depends on what you are trying to do.

 

0 0
replied on March 17, 2015 Show version history

So here is what is actually happening. I have three multi value fields. In another step i concatenated them down to one multi value. I want to see only what has changed from before a user opened the file and basically what they added. So I'm storing the values into a token at the beginning and then reading them again after. Maybe there is a better way where i can compare each value with each value of the other like maybe a nested for each value.

 

In the end i want to have a token with only new values, maybe there is a really simple way to do it I'm missing. 

0 0
replied on March 18, 2015

Joel, seems like the best approach would actually be with some creative usage of For Each Value loops or with a simple Script. The issue with using Pattern Matching here would likely be that the values of the fields might not be in the same order that you expect them to be in, from the description you provided (though maybe with a few more details about the specifics we could narrow this down further)

 

You can do this little trick to make this work: Say we have 2 MV tokens: 

MV1 is the original list

MV2 is the modified list

(you can also create a copy of MV2 called MV3 to do your work if you want to keep MV2 around)

Now add a For Each Value iterating thru MV1. 

For each value of MV1, modify MV2 using Assign Token Values; set its new value to itself (using "replace" rather than "append"), but only after applying the token function "Remove" with the current value you are iterating through as the value you are removing.

 

In other words, you are removing each value in MV1 from MV2. After this process, what's left of MV2 is whatever is not also in MV1, which should be the new values you want!

 

The workflow looks something like this:

 

 

Let me know if you have questions!

 

 

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.