?
Solved

RegEx replace upper case

Posted on 2005-04-29
3
Medium Priority
?
438 Views
Last Modified: 2012-08-13
Given
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.

0
Comment
Question by:lrr81765
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
dsacker earned 2000 total points
ID: 13897298
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:

<html>
<head><title>RegExp Tester</title></head>
<body>
<h2>RegExp Tester</h2>
<table>
  <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>
</table>
<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;
}
</script>
</body>
</html>
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 13898373
Here the RegExp version:

<script>

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

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

</script>

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 13918533
Why is this question still open? Do you need more help or some explanations?
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…
Suggested Courses

864 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