2

I want to capitalize letters that follow colons. Here is the code:

(replace-regexp-in-string ": \w" 'upcase ": really")

The result I expected is : Really. Instead I get : really.

Similarly, this also doesn't work:

(replace-regexp-in-string ": [:alpha:]" 'upcase ": really")

But this works:

(replace-regexp-in-string ": r" 'upcase ": really")

And this, too:

(replace-regexp-in-string ": [:alpha:]" 'upcase ": alright")

My LANG environment variable is set to en_US.UTF-8.

3
  • 2
    In the first example you are missing a backslash and in the second a set of braces. I.e. these regexps don't match the provided string.
    – politza
    Commented Jan 30, 2015 at 1:09
  • 2
    And I'm pretty sure your last example didn't work ☺
    – Malabarba
    Commented Jan 30, 2015 at 1:42
  • 1
    @Malabarba, there was an error in the example. I fixed it.
    – tmalsburg
    Commented Jan 30, 2015 at 5:42

1 Answer 1

5

You need to double the backslash in a Lisp string:

(replace-regexp-in-string ": \\w" #'upcase ": really")

See the Elisp manual, node Syntax for Strings.

And a char class has chars inside [], so put [:alpha:] inside [].

(replace-regexp-in-string ": [[:alpha:]]" #'upcase ": really")

See the Elisp manual, node Regexp Special.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.