2

how can you extract field- * but other than field-req

input:

form-field field-input field-req
form-field field-parents field-req
cell-header form-field field-input
form-field field-responsible field-req
form-field field-select cdsddsadsa
form-field field-select field-req
form-field field-textarea field-req
form-field field-textarea

output:

field-input
field-parents
field-input
field-responsible
field-select
field-select
field-textarea
field-textarea

I have this, but it does not meet

\bfield\-((?!.*req).*)\b

https://regex101.com/r/9y7pAV/1

1 Answer 1

3

You may use

/\bfield-(?!req\b)\w+/g

See the regex demo

Details

  • \b - a word boundary
  • field- - a literal substring
  • (?!req\b) - the must not be req and end of word boundary immediately to the right of the current location
  • \w+ - 1 or more word chars (replace with [a-zA-Z]+ to only match ASCII letters).
Sign up to request clarification or add additional context in comments.

Comments

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.