test
contains string, which checks for a particular pattern.
If pattern doesn't exist, find at least a character of pattern and it's position and re-frame the test
consisting of provided pattern.
- In scenario 1, pattern exists. So, no replacement.
test = "aebfz" pattern = "ebf" output = No replacement required
- In scenario 2, no pattern exists but
'b'
exists. After re-framing, out put should look like below (position of 'b' in test is 1. 'b' in pattern is '1')
> test = "abcdz" > pattern = "ebf" > output = "ebfdz"
- In Scenario 3, no pattern exists. But both 'b' and 'e' exists at different positions. So, possible output looks like below ('b' is '0' and 'e' is '4' in test)
> test = "bacde" > pattern = "ebf" > output1 = "ebfcde" (added 'e' before 'b') > output2 = "bacdebf" (added 'bf' after 'e')
- In scenario 4, no pattern exists. But char 'b' exists, so as output.
test = "xabdz" pattern = "ebf" Output = "xebfz"
- In scenario 5, no pattern exists. Output can be re-framed as below
test = "vwxyz" pattern = "ebf" Output1 = "ebfyz" Output2 = "vebfz" Output3 = "vwebf"
I'm thinking to mask and replace mechanism. For example: scenario 2
test = "abcdz"
pattern = "ebf"
new_test = "#b#dz" (should look like)
final_test = "ebfdz"
I don't know how it can be done. Just my approach. If my approach is not right, please let me know.