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: Desired: Add a negative attitude in the beginning. 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"]
= & Gt; ["Foo", "Bash", "Fuzz + Buzz", "X", "Bar"]
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
Post a Comment