0

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.

  1. In scenario 1, pattern exists. So, no replacement.
test = "aebfz"
pattern = "ebf"
output = No replacement required
  1. 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"
  1. 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')
  1. In scenario 4, no pattern exists. But char 'b' exists, so as output.
test = "xabdz"   
pattern = "ebf"    
Output = "xebfz"
  1. 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. Can you please help me here ? If my approach is not right, please let me know possible best option.

StackGuru
  • 421
  • 3
  • 16
  • Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Also, refer to [Learning Regular Expressions](https://stackoverflow.com/questions/4736) post for some basic regex info. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Aug 20 '20 at 14:47
  • @WiktorStribiżew will reg-ex be able to handle all above scenarios ? adding extra bits of chars and all other ? – StackGuru Aug 20 '20 at 17:17
  • can reg-ex handle position of string ? – StackGuru Aug 20 '20 at 17:17
  • I'm aware of reg-ex but not that great. Could you help me with few ? – StackGuru Aug 20 '20 at 17:18
  • @WiktorStribiżew any luck ? – StackGuru Aug 21 '20 at 21:08

0 Answers0