[Date Index] [Thread Index] [Author Index]
Operations on RegularExpression matches
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.