1.

Are there constants in JavaScript?

Answer»

Let’s say the FOLLOWING is our string with numbers:

VAR strNum = "only123!";

To fetch the digits from the above string, the following REGEXP is used:

/\d/G

Above we have set the g flag to perform global match.

The following is the code:

<html&GT;    <head>       <title>Regular Expression in JavaScript</title>    </head>    <body>       <script>         var strNum = "only123!";         var regExp = /\d/g;         document.write("String with numbers: "+strNum)         var res = strNum.match(regExp);         document.write("<br>Getting Digits = "+res);       </script>    </body> </html>

The output:

String with numbers: only123! Getting Digits = 1,2,3


Discussion

No Comment Found