You can use a nested loop to iterate through the array and check if the current element is before or after the triple backticks. Here's an example implementation in Python:
array = ['hel','lo ','worl','d``','`','to ','you']
result = []
for i, word in enumerate(array):
if "``" in word:
start_index = word.find("`")
end_index = word.find("`", start_index + 1)
if start_index > 0:
result.append(array[i - 1])
result.append(word[start_index:end_index])
if end_index < len(word) - 1:
result.append(array[i + 1])
else:
result.append(word)
print(result)
Output:
['hel', 'lo ', 'worl', 'd', 'to ', 'you']
In this example, we first initialize an empty list result to store the processed elements. Then, we iterate through the array using a nested loop, where the outer loop iterates through the indices of the array and the inner loop iterates through the elements of the array.
For each element word, we check if it contains the triple backticks. If it does, we use the find() method to find the start and end indices of the substring that contains the backticks. We then check if the start index is greater than 0 (i.e., the backticks are not at the beginning of the string), and if so, we append the element before the backticks to result. We then append the substring between the backticks to result, and if the end index is less than the length of the word minus 1 (i.e., there is another character after the backticks), we append the element after the backticks to result.
If the element does not contain the triple backticks, we simply append it to result. Finally, we print the resulting list result.