Input:
Result:
Some time developers need a code to extract number from string that contains alphabets, special characters. Below is a JavaScript function that does the job for you.
Code simply extracts number if found else returns empty string.
JavaScript RegExp \d Metacharacter is used to find a digit from 0-9.
In above function you can replace /\d+/g with /[0-9]+/g
both will generate same result. The only difference is \d is a short name of [0-9]
Result:
Some time developers need a code to extract number from string that contains alphabets, special characters. Below is a JavaScript function that does the job for you.
Code simply extracts number if found else returns empty string.
Function:
JavaScript RegExp \d Metacharacter is used to find a digit from 0-9.
In above function you can replace /\d+/g with /[0-9]+/g
both will generate same result. The only difference is \d is a short name of [0-9]
No comments