-1

What's the PCRE2 regular expression syntax to match a specific word if and only if it contains at least one uppercase letter? I can currently match both conditions individually (^foobar$ or [A-Z]+), but don't know how to combine as a compound conditional. Expected results for testing "foobar":

✅ Foobar    ✅ fooBAR    ❌ foobar    ❌ Foobars   ❌ sFoobar
anthumchris
  • 8,245
  • 2
  • 28
  • 53

1 Answers1

0

Positive lookahead assertions (?=...) and local options (?i:...) can be used:

^(?=.*[A-Z])(?i:foobar)$

Tests: https://regex101.com/r/JdQlaQ/1

anthumchris
  • 8,245
  • 2
  • 28
  • 53
rob mayoff
  • 375,296
  • 67
  • 796
  • 848