Reputation: 93
I want to match [abcDe] but not [abcde]. I used (?=\[([^\[\]]*)\])
to match all between brackets, but then I tried [A-Z]+(?=\[([^\[\]]*)\])
to only match between brackets when it contains an uppercase and it doesn't work.
Does anyone know how to solve this ?
Upvotes: 1
Views: 463
Reputation: 163467
You might use
\[[^][A-Z]*[A-Z][^][]*]
The pattern matches:
\[
Match the opening square bracket[^][A-Z]*
Optionally repeat matching any char except [
]
or an uppercase char[A-Z]
Match a single uppercase char[^][]*
Optionally repeat matching any char except [
]
]
Match the closing square bracketUpvotes: 2
Reputation: 20747
You don't specify the regex flavor but this could work:
(?<=\[)[a-zA-Z]*[A-Z][a-zA-Z]*(?=\])
(?<=\[)
- behind me is an opening bracket[a-zA-Z]*
- allow upper or lower case chars[A-Z]
- require one uppercase char[a-zA-Z]*
- allow upper or lower case chars(?=\])
- ahead of me is a closing brackethttps://regex101.com/r/iz5Dtl/1
Upvotes: 1