两个字符串之间的正则表达式,不包括字符串

时间:2018-05-09 17:19:34

标签: regex

我正在尝试使用正则表达式从下面的XML中选择常量,其中常量是COM_CCJET_FORM_ * _NAME 除非常量包含FIRST_NAME或LAST_NAME

<field name="name" type="text" filter="safehtml" class="input-xxlarge input-large-text"
label="COM_CCJET_FORM_LBL_WORKORDER_NAME" description="COM_CCJET_FORM_DESC_WORKORDER_NAME" required="true"
hint="COM_CCJET_FORM_LBL_WORKORDER_NAME" />

<field name="first_name" type="text"
label="COM_CCJET_FORM_LBL_CONTRACTOR_FIRST_NAME" description="COM_CCJET_FORM_DESC_CONTRACTOR_FIRST_NAME"
required="true" menu_published="0" filter="string" directory_stripext="true"
directory_hidenode="true" directory_hidedefault="true"
alias_generator="2135354" heading="h4" close="true" option_on="Yes"
option_off="Yes" />

我可以使用正则表达式获得COM_CCJET_FORM _ * _ NAME的任何内容:

COM_CCJET_(.*?)_NAME

但我无法弄清楚如何告诉正则表达式排除&#34; FIRST&#34;

1 个答案:

答案 0 :(得分:1)

使用负面的lookbehinds:

COM_CCJET_([^"]*?)(?<!FIRST|LAST)_NAME

Demo