perl - Match all uppercase words only if there's a lowercase in the string, with one regex -


I stumbled upon this seemingly insignificant question, and I'm stuck on it. I have a string in which I want to match one reggae to all uppercase words only if there is at least one lowercase letter in the string somewhere.

Actually, I want each of these lines (we can assume that I will apply different regex in each line in each line, some multi-line handling is not required): < / P>

  ab captures ABC // matches or ABC ABC 12 CDs / matches or captures ABC, captures CD ABC Day matches or captures Nothing (no lowercase) ABC 23 Day EFG // matches or AB I have been using PCE as a ragex flavor (I know that some other flavors can be used for Variable Letter Look-back is allowed).  

Updates after comments

Obviously, there are a lot of easy solutions if I'm using several regex or programmable languages ​​that I use to regex I'm using to call (like validate the string first, by searching for a lowercase letter, match all two uppercase words with different regex).

My goal is to find a way to do this with a regex.

I have no technical compulsions for this obstacle. If you are trying to raise your, or curiosity, or my regex skills, then take it as a practice of style: this task (first) hence was simple that I would like to know A regex alone can get it if it can not happen, so why would I want to understand.

Or if it can, it has not been designed for these tasks, so I want to know - or at least "these types of irregular tasks", so that I meet them Can choose the right solution.


So, is it possible in a reggae?

update
then \ g In the situation of the situation at the beginning of the match is set.
Which is in multi-line mode, BOS should be a special case.
Even if bosstrings are a ballin, if this argument fails (? = ^. * [Az]) , the Is set as (default?) And the UC words are found without validation.

  (? =? \ * * [AG]). *? \ B ([AZ] +) \ b | (?! \ A) (?: (? =? ? ^. * [AG]) | \ j * *? B ([as] +) \ b))  

update 2 Posted in Future Generation.
After some discussion with Robin, the above regex can be re-applied to:

  # (?: (? = ^. * [Az ]) | (?! \ A) \ j) *? \ B ([: =?. *. * [AG]) #BOL, check if the line has a lower case letter # or (?! \ A) # not on BOS (string of Start, where \ g is in a matching state) #G # Start the match at the end of the last match (if the previous match state)). *? \ B ([A-Z] +) # (1), found UC word \ b  

Pearl test case:

  $ / = undef; $ Str = & lt; Data & gt ;; @ary = $ str = ~ / (?: (? = ^. * [A-z]) | (??? a) \ G). *? \ B ([A-Z] +) \ b / mg; Print "@arry", "\ n ------------- \ n"; While ($ str = ~ / (?: (? = ^. * [Az]) | (??? a) \ G). *? \ B ([AZ] +) \ b / mg) {print "$ 1 "; } ABC ABC ABC 12 CD ABC DT ABC 23D EFG A  

Output >>

  ABC ABC CD ABC De ABC De EFG - ------------ ABC ABC CD ABC De ABC de EFG  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -