I need to make a regular expression match that contains a text component that comes from a variable.
The character vector contained in the variable is long and may contain characters that are operators, quantifiers, metacharacters, etc in Matlab's regular expression engine.
Is there a way to match that text component as is?
Using strfind() would be non-ideal because my desired match comprises of some pattern before the text component, exact match of the text component, and some pattern after. The text can be matched by itself, but matching the components before and after would be inconvenient.
An example (which doesn't necessarily fully capture the inconvenience) would be:
pat_b='%%\s+(?<name1>abc\d{6})\s+'; % pattern before
txt='asdf(1).qwer=[123:456,789]; zxcv;'; % text from variable
pat_a='\s+%%\s+(?<name2>\w{6})'; % pattern after
I tried using
f_txt=@()txt;
expression=[pat_b,'(??@f_txt())',pat_a];
regexp(txt_to_search,expression,'names'),
But couldn't get a correct match. Most likely, the result of f_txt() was read without escaping the special characters.