Welcome to WebmasterWorld Guest from 54.158.166.6

Forum Moderators: open

Message Too Old, No Replies

regexp: convert upper case to lower case

   
6:23 pm on Mar 16, 2008 (gmt 0)

10+ Year Member



could anyone tell me how to do this, in the format of replace(x,x)? i have a regexp cheat sheet that has the posix notations as [:upper:] and [:lower:] but firebug throws an error when i try to use this.

id imagine this is quite simple, just cant track it down. thanks!

7:04 pm on Mar 16, 2008 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You have two ways of approaching this:

1) In JavaScript: string = string.toUpperCase();
2) Use CSS to display it in all caps regardless of string casing

11:40 pm on Mar 16, 2008 (gmt 0)

5+ Year Member



FYI: Javascript uses perl-style regular expressions, not posix.

replace(/x/ig, 'X') will find all occurrences of 'x' or 'X' and replace them with 'X', and
replace(/x/ig, 'x') will find all occurrences of 'x' or 'X' and replace them with 'x',
but the toUpperCase() and toLowerCase() methods are the preferred way to shift case with an arbitrary string.