3

I found the following code from this question, regex to match everything until it finds 2 upper case characters?

^.*(?=\b(?:[^\sA-Z]*[A-Z]){2})

however my question is slightly different then the OP

I want to match everything up to the upper case in the following string, the rules should match everything until it negative lookaround finds 2 uppercase characters and then match everything inbetween from the 1st uppercase until the start of the 2nd uppercase character

so I Want (continue from op example)

Http is an HttpHeader

is to get Http is an Http

instead of Http is an which OP is getting in posted thread

Community
  • 1
  • 1
user1973125
  • 83
  • 1
  • 3

4 Answers4

0

Seems overly comp. to me

preg_match( '/[^A-Z]+/', $str, $res );
Kohjah Breese
  • 3,772
  • 5
  • 30
  • 44
0
preg_match('/[^A-Z]*([A-Z]{1}[^A-Z]*[A-Z]{1}[^A-Z]*)/', $str, $res);
Jompper
  • 1,372
  • 8
  • 15
0

use this pattern ^.*?(?=\b(?:[^\sA-Z]*[A-Z]){2}).+?(?=[A-Z]) Demo

alpha bravo
  • 7,520
  • 1
  • 16
  • 23
0
([A-Z].*?\w+(?=[A-Z]))

You may follow the above regex. That's so simple and yet fast. See matched groups here: Live demo

revo
  • 45,845
  • 14
  • 70
  • 113