简短的问题
是否可以使用正则表达式来匹配未出现在其他较长字符串中的字符串?(我正在使用 MATLAB)
例子
shortString = {'hello', 'there'};
longString = {'why hello there', 'hello, my friend', 'hello and goodbye'};
wholeString = ['"why hello there", said one guy. The other guy over ' ...
'there said hello, my friend. hello and goodbye, said the ' ...
'third guy. So let''s all say hello!'];
在此示例中,我想匹配shortString
in的元素wholeString
,只要它们不wholeString
作为 的元素的子字符串出现在longString
。
在上面的例子中,我只想匹配'hello'
from'So let''s all say hello!'
和'there'
from 'The other guy over there'
。
具体问题
我正在编写一个函数,该函数将标记函数顶部的帮助注释,以准备使用 MATLABpublish
函数发布它(请参阅Publishing Markup)。除了标记函数的语法之外,我还想标记函数的任何输入/输出,它们出现在语法之外。假设我以某种方式从函数中提取了帮助注释。以下是一些示例评论。
% SYNTAX
% x = somefunction(y)
% [out1, out2] = somefunction(in1, in2)
%
% DESCRIPTION
% x = somefunction(y) does something to y and returns x. I also dont wan't
% your answer to match the 'y' in 'your' or ''y''.
%
% [out1, out2] = somefunction(in1, in2) does something else with in1 and
% in2. Then it returns out1 and out2.
用我当前的方法标记这些评论后,我有以下内容
%% Syntax
% x = somefunction(y)
% [out1, out2] = somefunction(in1, in2)
%
%% Description
% |x = somefunction(y)| does something to y and returns x. I also dont wan't
% your answer to match the 'y' in your or ''y''.
%
% |[out1, out2] = somefunction(in1, in2)| does something else with in1 and
% in2. Then it returns out1 and out2.
我想让每个输入和输出参数在“描述”部分中显示为等距。我希望最终文本是
%% Syntax
% x = somefunction(y)
% [out1, out2] = somefunction(in1, in2)
%
%% Description
% |x = somefunction(y)| does something to |y| and returns |x|. I also dont wan't
% your answer to match the 'y' in 'your', or ''y''.
%
% |[out1, out2] = somefunction(in1, in2)| does something else with |in1| and
% |in2|. Then it returns |out1| and |out2|.
问题是我不能只匹配输入参数,或者我也会在已经是单行距的语法部分匹配它们。
我可以使用一个包含每个语法定义的元胞数组、一个包含每个输入参数的元胞数组和一个包含每个输出参数的元胞数组。
syntax = {'x = somefunction(y)', '[out1, out2] = somefunction(in1, in2)'};
inputs = {'y', 'in1', 'in2'};
outputs = {'x', 'out1', 'out2'};