Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ClearAll[foo, labeledFoo];
- labeledFoo = {"FooBarBazQuux", foo};
- labeledFoo /. hdr_String :>
- StringReplace[hdr, l_?LowerCaseQ ~~ U_?UpperCaseQ :> l <> " " <> U]
- (* {"Foo Bar Baz Quux", foo} *)
- labeledFoo /. hdr_String :>
- StringReplace[hdr, l_?LowerCaseQ ~~ U_?UpperCaseQ :> l <> " " <> U] /.
- {hdr_String, x_} :> (hdr -> x)
- (* "Foo Bar Baz Quux" -> foo *)
- labeledFoo /. {hdr_String, x_} :> (Rule @@ {StringReplace[hdr,
- l_?LowerCaseQ ~~ U_?UpperCaseQ :> l <> " " <> U], x})
- (* "Foo Bar Baz Quux" -> foo *)
- labeledFoo /. {hdr_String, x_} :> (StringReplace[hdr,
- l_?LowerCaseQ ~~ U_?UpperCaseQ :> l <> " " <> U] -> x)
- (* "Fo" ~~ l <> " " <> U ~~ "a" ~~ l <> " " <> U ~~ "a" ~~
- l <> " " <> U ~~ "uux" -> foo *)
- StringReplace["FooBarBazQuux",l$_?LowerCaseQ~~U$_?UpperCaseQ:>l<>" "<>U]
- {{1, 2}, 3} /. {x_List, y_Integer} :>
- Rule[
- Replace[x, {l_Integer, u_Integer} :> l + u],
- y
- ]
- (* l + u -> 3 *)
- {x_, x+1} -> x^2
- {{1, 2}, 3} /. {x_List, y_Integer} :>
- Block[{yy = y},
- Rule[
- Replace[x, {l_Integer, u_Integer} :> l + u],
- yy]
- ]
- (* 3 -> 3 *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement