Chad Caldwell
Chad Caldwell

Reputation: 274

Regular expression inbetween two strings, excluding string

I am trying to use regex to select the constants from the XML below where the constant is anything COM_CCJET_FORM_ * _NAME Except when the constant contains either FIRST_NAME or 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" />

I am able to get anything that has COM_CCJET_FORM_*_NAME with the regex:

COM_CCJET_(.*?)_NAME

But I can't figure out how to tell the regex to exclude "FIRST"

Upvotes: 1

Views: 34

Answers (1)

L3viathan
L3viathan

Reputation: 27323

Use negative lookbehinds:

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

Demo

Upvotes: 1

Related Questions