In the Data below i want to POL and corresponding value from Part so basically where ever is POL placed we need to get same number of value from part column:
Data:
Ops | Part |
key-ID-ISSUE-POL-COT | 856-658-985-963-458 |
key-ID-ISSUE-POL | 968-548-785-9635 |
key-ID-ISSUE-POL-COT-DT | 4563-568-475-96242-544 |
Result:
Ops | Part |
POL | 963 |
POL | 9635 |
POL | 96242 |
Solved! Go to Solution.
@eaglepath
This is an example for a post that I will not bother helping. There are several people that suggested workable solutions, I tried each and worked correctly, and you are just nattering that they are not working not even sharing the issue that you are facing from your end. If it is working for others and not for you then you are doing something wrong.
You have here at least 4 workable solutions. Good luck.
@binuacs Thnks for the solution worked really well.
@20-Binuacs
Your solution worked really well. Thanks
Can you please explain this formula as well? Thanks!
hope this helps
REGEX_Replace([Ops], "^(([^-]+-){"+TOSTRING([Position]-1)+"})([^-]+).*", "$3")
[Ops]:
This is the input string on which the regular expression will be applied.
"^(([^-]+-){"+TOSTRING([Position]-1)+"})([^-]+).*":
This is the regular expression pattern that the function uses to match portions of the input string.
Let's break down this regular expression:
"^": Matches the start of the string.
"(([^-]+-){"+TOSTRING([Position]-1)+"})":
"[^-]+": Matches any sequence of characters that does not include a hyphen (-).
"[^-]+-": Matches a sequence of characters followed by a hyphen.
"{"+TOSTRING([Position]-1)+"}": The TOSTRING([Position]-1) dynamically calculates a number based on the Position field minus 1. This number dictates how many occurrences of the preceding pattern ([^-]+-) to match. The result is the first N-1 segments before the hyphen.
"([^-]+)": Captures the segment immediately following the N-1 segments of hyphen-separated values. This is the part of the string you're interested in.
".*": Matches the rest of the string, but it's not captured because we are only interested in the previous capturing group.
"$3":
This indicates what the replacement string should be. The $3 refers to the third captured group in the regular expression.
In this pattern, $3 corresponds to ([^-]+), which is the N-th segment of the hyphen-separated values.
Example Walkthrough:
Suppose [Ops] is "A-B-C-D-E" and [Position] is 3.
"^(([^-]+-){"+TOSTRING([Position]-1)+"})":
TOSTRING([Position]-1) = 2, so this will match the first 2 hyphen-separated groups "A-B-".
"([^-]+)":
This will capture the next segment, which is "C".
".*":
This matches the rest of the string, "D-E", but this is not captured.
"$3":
The final output will be "C", which is the third segment in the hyphen-separated list.
Summary:
The REGEX_Replace function in your case is used to extract a specific segment from a hyphen-separated string based on the Position value. It finds the Position-th segment in the string and returns it as the result.