How to use JS to intercept the digital __js in a string

Source: Internet
Author: User
Like what
var v = "I want to ask a question 1098";
var v= "I'm 0 to ask questions"
var v= "I still want to ask 987"
Wait
I want 1098, 0, 987 inside.
There is definitely a set of numbers in a string, the number of which is not fixed, this group of numbers is composed of random 0~9, at least one, such as maybe only a 0.

With JS how to achieve.


<script>
var v = "I want to ask 1098";
S= ""
for (i=0;i<v.length;i++)
{
if ("0123456789". IndexOf (V.substr (i,1)) >-1)
s+=v.substr (i, 1
}
alert (s)

</script>


<script>

var str = "People's Republic of China 04314fdsa";
Alert (Str.replace (/^[^\d]* (\d+) [^\d]*$/, "$")];

</script>


<script language=javascript>
function getn (s)
  {return s.replace (/[^0-9]/ig, " Alert (
getn ("I want to ask 1098")) Alert (
getn ("I want to ask you 0)") Alert
(GETN ("I want to ask 987"
)) </ script>


<script>
var  v = "I still want to ask questions 987";
Alert (V.match (/\d+/ig));
</script>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.