RegEx replace upper case

Posted on 2005-04-29
Last Modified: 2012-08-13
Sum(ItemOne + ItemTwo + ItemThree)
CalcLate( something0

I need to have javascript that would look at all of the characters before the ( and replace them with toLower().

I'd like to do this with the replace (regex, replacement) but can't seem to get the regex to work.

Question by:lrr81765
    LVL 20

    Accepted Solution

    You may find RegExp a bit more complex than you want. Play around with this example, and let me know if this is close to what you're looking for:

    <head><title>RegExp Tester</title></head>
    <h2>RegExp Tester</h2>
      <tr><td>RegExp: </td><td><input type=text name=inpRegExp></td></tr>
      <tr><td>Value:  </td><td><input type=text name=inpValue></td></tr>
      <tr><td colspan=2><input type=button value="Return New Value" onclick="retValue()"></td></tr>
      <tr><td>Result: </td><td><input type=text name=inpResult readonly></td></tr>
    <script language=javascript>
    function retValue() {
        var strValue  = inpValue.value;
        var intPos    = strValue.indexOf('(');
        var newValue  = strValue.substring(0, intPos).toLowerCase() + strValue.substring(intPos, strValue.length);
        inpResult.value = newValue;
    LVL 63

    Expert Comment

    Here the RegExp version:


    myText = "Sum(ItemOne + ItemTwo + ItemThree)\nCalcLate( something0";

    alert(myText.replace(/\w+\s*\(/g,function(p){return p.toLowerCase()}));


    LVL 63

    Expert Comment

    Why is this question still open? Do you need more help or some explanations?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 for Beginning Beginners

    Are you looking for an efficient introduction to HTML5? Have you tried other HTML5 courses and found them too complex? Do you need just the basics of HTML5 to use with Wordpress or other content management system? If you said yes to any of these questions, this course is for you.

    In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now