2010-04-02 73 views
0

如何查找行号中的数字可能不在开头。例如:“d:\\ 1.jpg”按行查找号码。 Javascript

谢谢。

+1

你将不得不解释你需要做什么好了很多,或者这可能被关闭。试着告诉我们你想达到的目标。 – 2010-04-02 12:08:59

回答

1

您使用与RegExp对象正则表达式:

var myRegEx = /\d+/; // RegEx to find one or more digits 

var myMatch = myRegEx.exec("d:\\1.jpg") 
1

您可以使用regexp

var match = "testing 123".match(/\d/); 
if (match) { 
    alert(match.index); // alerts 8, the index of "1" in the string 
} 

使用String#match,使用 “数字” 类(\d)在字面正则表达式传递。

和/或你可以抓住开始找到的第一个数字的所有连续数字:

var match = "testing 123".match(/\d+/); 
if (match) { 
    alert(match.index); // alerts 8, the index of "1" in the string 
    alert(match[0]); // alerts "123" 
} 

这些链接到Mozilla的文档,因为它是相当不错的,但这些都不是具体的Mozilla的功能。