I’ve not yet mastered regex, so would appreciate your help with the code.
I need to replace all lines that:
- start with brackets or parentheses;
- which may contain either a regular number of up to 3 digits or a combination of up to 3 letters;
- which may be followed by a period;
- which digis or the numbers may or may not be inside or tags.
Here’s the example of what it needs to be replaced with:
(1)blahblah => %%(1)|blahblah
(<i>iv</i>.) blahblah => %%(<i>iv</i>.)|blahblah
[b] some stuff => %%[b]| some stuff
So the regex will need to recognize if it needs to be applied to the particular string, and if yes, put %% in the beginning of the line, then put the stuff inside the brackets, then put a pipe | (if there is a space between the brackets and the rest of the text, delete the space), and finally place the rest of the line.
So, let’s assume I have an array that I’m trying to run through the function that will either process the string (if it matches the criteria), or return it unchanged.
I only need to know how to write the function.
Thanks
Here is my version.
It uses the fallback regular expression if the first one doesn’t match (as agreed upon previously).
Demo
Code:
First regular expression expanded: