ruby - How do I split a string on capitals unless preceded by a '+' -


I have a simulated string, which I would like to split capitals on different words, until one capital Do not be the first '+':

Partitioning in Ruby is quite simple: s.split (/ (? = [AZ]) /) But I do not know how For example:

  s = "FooBashFizz + BuzzXBar" p s.split (/ (? = [AZ]]) /) =) & gt; ["Foo", "Bash", "Fizz +", "Buzz", "X", "Bar"]   

Desired:

  = & Gt; ["Foo", "Bash", "Fuzz + Buzz", "X", "Bar"]    

Add a negative attitude in the beginning.

  irb (main): 001: 0> S = "FooBashFizz + BuzzXBar" = & gt; "Foobhphis + BuzzExber" IRB (Main): 002: 0> S.split (/ (? & Lt !! \ +) (? = [A-Zed]) /) = & gt;    Explanation:   
  • (? & Lt ;! \ +) indicates that the predecessor It will also be, but there will be no + symbol.
  • (? = [AZ]) emphasizes that the lower letter should be an uppercase letter.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -