0

Have to divide tracking code of varying length a|b|c or a|b|c|d

I always want 'a' to go to 'Name' 'b' to go to 'ID' 'c' to go to 'Title'

So have set up the below rule

#   Select Rule Type    Enter Match Criteria    Set Classification  To
1   Regular Expression  ^(.+)\|(.+)\|(.+)$  Name            $1
2   Regular Expression  ^(.+)\|(.+)\|(.+)$  ID              $2
3   Regular Expression  ^(.+)\|(.+)\|(.+)$  Title           $3

This works fine for a|b|c, however for varying length like a|b|c|d result is not correct and comes as follows:--

'a|b' to 'Name' 'c' to 'ID' 'd' to 'Title'

Can you suggest how to fix this so that the result for a|b|c|d comes as

a' to go to 'Name' 'b' to go to 'ID' 'c|d' to 'Title'

Kumar
  • 3
  • 3
  • Could you add some example input and what should match on that input – vallentin Mar 22 '17 at 11:30
  • I answered with a regex that is dividing your inputs based on character |. However reading again your question is not really clear what you actually need. So if my answer is not what you need can you provide more detailed information about it? – rakwaht Mar 22 '17 at 11:53
  • @Vallentin Lets say as an example BRightcove|ya0o-0SRKPkeds|WONDERGOAL from the halfway line! | Liam Kelly | Reading FC | Ireland u19s vs Sweden | 12.10.13 ------------------------------------------- Brightcove to go to 'Player NAme' ya0o-0SRKPkeds to 'ID' and the rest WONDERGOAL from the halfway line! | Liam Kelly | Reading FC | Ireland u19s vs Sweden | 12.10.13 to the 'Title' – Kumar Mar 22 '17 at 12:07

1 Answers1

0

You should try this one that is working for 1 to N elemnts in your list.

[^\|]+?[^\|]*

You can also try it in this DEMO.

EDIT: According to your need I suggest this regex:

(.*?)\|(.*?)\|(.*)

You can also take a look at the DEMO.

Quick explanation from here: The .+? part is the un-greedy version of .+ (one or more of anything). When we use .+, the engine will basically match everything. Then, if there is something else in the regex it will go back in steps trying to match the following part. This is the greedy behavior, meaning as much as possible to satisfy.

When using .+?, instead of matching all at once and going back for other conditions (if any), the engine will match the next characters by step until the subsequent part of the regex is matched (again if any). This is the un-greedy, meaning match the fewest possible to satisfy.

Community
  • 1
  • 1
rakwaht
  • 3,666
  • 3
  • 28
  • 45
  • This is good but for varying length I only have 3 buckets so the first value in the pipe delimited should go to the first bucket, second value should go to the second and the thirs and rest should go to the last bucket e.g. Lets say as an example BRightcove|ya0o-0SRKPkeds|WONDERGOAL from the halfway line! | Liam Kelly | Reading FC | Ireland u19s vs Sweden | 12.10.13 ------------------------------------------- Brightcove to go to 'Player NAme' ya0o-0SRKPkeds to 'ID' and the rest WONDERGOAL from the halfway line! | Liam Kelly | Reading FC | Ireland u19s vs Sweden | 12.10.13 to the 'Title' – Kumar Mar 22 '17 at 12:09