0

so far I have this

(?:(?![A-Z]{2,}).)*

which matches everything until HTTPHEADER, however I want it to stop when it sees HttpHeader

how to do that?

so if I have string like Http is an HttpHeader

it should match Http is an

  • Does that mean you want to step the match when it sees the same two upper case characters? And does that mean that the match in `HttpHeader` should be `HttpH`? – Jerry Dec 21 '13 at 10:24
  • it should see HttpHeader and stop, edited – user3117904 Dec 21 '13 at 10:26
  • So, if the string is: `Http is a Nice Header`, it should match `Http is a Nice `? And if you have `Http is a Nice thiNg to Have`, should it match `Http is a Nice thi`? – Jerry Dec 21 '13 at 10:30
  • @Jerry not it should match Http is a Nice thiNg to Have, it does not matter where the capital letter is just that there is no 2 capital letters in any word – user3117904 Dec 21 '13 at 10:35
  • Then I think the string in your question is wrong; it should be `Http is an HttpHeader`, right? – Jerry Dec 21 '13 at 10:41
  • ah of course sorry!!! – user3117904 Dec 21 '13 at 10:49

3 Answers3

0

You could perhaps use this:

^(?:(?!(?:\S*[A-Z]){2}).)+

regex101 demo

(?:\S*[A-Z]){2} will match only if a word has two uppercase characters.

And since this is in a negative lookahead, the match will stop only if a word with two uppercase characters is found ahead.

Jerry
  • 70,495
  • 13
  • 100
  • 144
0

using Jerry's suggestion and this pattern is much more efficient
^.*(?=\b(?:[^\sA-Z]*[A-Z]){2}) Demo

alpha bravo
  • 7,838
  • 1
  • 19
  • 23
0
(.*?(?=[A-Z]\S*[A-Z]))

Why should we make it hard?! Live demo

revo
  • 47,783
  • 14
  • 74
  • 117