Operations on RegularExpression matches
- To: mathgroup at smc.vnet.net
- Subject: [mg119991] Operations on RegularExpression matches
- From: Jon Joseph <josco.jon at gmail.com>
- Date: Mon, 4 Jul 2011 06:44:57 -0400 (EDT)
All: I have string of all lower case letters: string = "this is a string" I wish to capitalize the first letter: StringReplace[string, StartOfString ~~ x_ -> ToUpperCase[x]] (* Does want I want *) Now I try to do the same thing using RegularExpression: StringReplace[string, RegularExpression["(^.)"] -> ToUpperCase["$1"]] which fails (returns original string without capitalization). I know the match is occurring since StringReplace[string, RegularExpression["(^.)"] -> ToUpperCase["$1X"]] returns "tXhis is a string" What am I missing about using the matched part of a regular expression? Thanks.