Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-26-2012, 04:00 AM   PM User | #1
otnj2ee
Regular Coder

 
Join Date: Apr 2007
Posts: 174
Thanks: 17
Thanked 0 Times in 0 Posts
otnj2ee is an unknown quantity at this point
RegExp

For a string of the formats: abc_def_ghl or abcd_xyz, abc_def_ghl_k, etc

I like to replace the "_char" with the uppercased char, for example:

abc_def_ghl --> abcDefGhl

abcd_xyz --> abcdXyz

abc_def_ghl_k --> abcDefGhlK

etc.

What is the RegExp for it?


Thanks
otnj2ee is offline   Reply With Quote
Old 10-26-2012, 08:14 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,260
Thanks: 10
Thanked 532 Times in 526 Posts
devnull69 will become famous soon enough
Try this
Code:
var myString = "abcd_ef_g_hij";
myString = myString.replace(/([a-z]*)(_)([a-z])/g, function(match, p1, p2, p3) {return p1+p3.toUpperCase();});
console.log(myString); // will give you abcdEfGHij
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:05 AM.


Advertisement
Log in to turn off these ads.