1

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"

1 Answer 1

1

Use negative lookbehinds:

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

Demo

Sign up to request clarification or add additional context in comments.

7 Comments

Or equivalently, ...(?<!FIRST|LAST)...
Nice! I can accept correct answer in 9 min (so SE tells me). Thanks!
Also, I would suggest something like \w+ instead of .*? - since the latter could get all sorts of weird matches for odd input e.g. label="COM_CCJET_FOO" ... label="COM_CCJET_FORM_LBL_WORKORDER_NAME"
@TomLord I tried it with an additional set of parens first, and regex101 told me that assertions have to be fixed-length. Updating
It depends on the regex library. Since OP didn't mention which language/tool they're using, I don't know what's supported (including whether or not negative lookbehinds are supported!)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.