Reputation: 23
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
Upvotes: 2
Views: 51
Reputation: 627607
You may use
/\bfield-(?!req\b)\w+/g
See the regex demo
Details
\b
- a word boundaryfield-
- 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).Upvotes: 3