MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Operations on RegularExpression matches

  • To: mathgroup at
  • Subject: [mg119991] Operations on RegularExpression matches
  • From: Jon Joseph <josco.jon at>
  • Date: Mon, 4 Jul 2011 06:44:57 -0400 (EDT)


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"]]


	"tXhis is a string"

What am I missing about using the matched part of a regular expression? 


  • Prev by Date: Re: Font and Style problems using Image to create bitmaps of Plots/Charts etc
  • Next by Date: Numerical accuracy/precision - this is a bug or a feature?
  • Previous by thread: Re: Insoluble marbles-in-urn problem?
  • Next by thread: Re: Operations on RegularExpression matches