Nati323 Posted March 19, 2015 Share Posted March 19, 2015 hello, i want to uppercase the first char in any new line, i try to do this: str.replace(/(^.)/gm, "$1".toUpperCase()); but, its not working, some ideas? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 19, 2015 Share Posted March 19, 2015 I'm not quite sure if that will work, although if it would then you'll need to move the ^ outside of the match. You should be checking for ^(.) I believe. See if that works first. Link to comment Share on other sites More sharing options...
Nati323 Posted March 19, 2015 Author Share Posted March 19, 2015 this is not the case, if you try to bold it like this: str.replace(/(^.)/gm, "<b>$1</b>"); its works, anyway i try to solve this with function, i says maybe its work, so i did: function toup($m) { return $m.toUpperCase(); }document.getElementById("demo").innerHTML = str.replace(/^(.)/gm, toup("$1")); its dosent work, i dont know why, if i try to use the function like that: toup("hello") its returns HELLO, but with the reg match its dosent work. i thought that maybe the match dosent transform to the function, but if you change the function to: function toup($m) { return $m + "abc" } you will see the match + abc, so the match did transform to the function,so i am at a loss.i dont understand where the problem is... Link to comment Share on other sites More sharing options...
justsomeguy Posted March 19, 2015 Share Posted March 19, 2015 If you give it a function you don't say what the parameters are, you just give it the function: str.replace(/^(.)/gm, toup);It passes the list of parameters automatically, there's a description about what it passes to the function here:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter Link to comment Share on other sites More sharing options...
Nati323 Posted March 20, 2015 Author Share Posted March 20, 2015 WOOOOOOWWWWWWWWW WORKS thanks :} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now