admin管理员组文章数量:1400038
I want the regular expression for the data of type dd.d.dd.ddddd or dd.d.d.ddddd,each d is for a digit between 0-9 and the regular expression should represent both the formats. I am working in java script.I have tried the following code.but it is not working for all the input strings.
<p id="demo">my string</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
//var regExp1=/[1-4]+\.[1-4]+\.[1-4]+\.[0-9]+$/;
var regExp1=/[1-4][1-4]\.[1-4]\.[1-4][1-4]\.[0-9][0-9][0-9][0-9][0-9]$/;
//var regExp1=/[0-9][0-9]\.[0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9][0-9]$/;
var str="Version of C:\hjkl.dll:14.6.17.90505 working File Versn:18.1.9.17083,stopped file:13.1.14.25059 absjhdhgh";
var mystring=str.split(regExp1);
document.getElementById("demo").innerHTML=mystring;
}
</script>
Desired output is:
Version of C:\hjkl.dll:
working File Versn:
,stopped file:
absjhdhgh
I want the regular expression for the data of type dd.d.dd.ddddd or dd.d.d.ddddd,each d is for a digit between 0-9 and the regular expression should represent both the formats. I am working in java script.I have tried the following code.but it is not working for all the input strings.
<p id="demo">my string</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
//var regExp1=/[1-4]+\.[1-4]+\.[1-4]+\.[0-9]+$/;
var regExp1=/[1-4][1-4]\.[1-4]\.[1-4][1-4]\.[0-9][0-9][0-9][0-9][0-9]$/;
//var regExp1=/[0-9][0-9]\.[0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9][0-9]$/;
var str="Version of C:\hjkl.dll:14.6.17.90505 working File Versn:18.1.9.17083,stopped file:13.1.14.25059 absjhdhgh";
var mystring=str.split(regExp1);
document.getElementById("demo").innerHTML=mystring;
}
</script>
Desired output is:
Version of C:\hjkl.dll:
working File Versn:
,stopped file:
absjhdhgh
Share
Improve this question
edited Sep 10, 2013 at 9:56
Jerry
71.6k14 gold badges104 silver badges146 bronze badges
asked Sep 10, 2013 at 9:47
DevRes2721608DevRes2721608
381 silver badge5 bronze badges
0
3 Answers
Reset to default 5Try with following regex:
\d{2}\.\d\.\d{1,2}\.\d{5}
Example:
var str = "Version of C:\hjkl.dll:14.6.17.90505 working File Versn:18.1.9.17083,stopped file:13.1.14.25059 absjhdhgh";
var regExp1 = /\d{2}\.\d\.\d{1,2}\.\d{5}/;
var output = str.split(regExp1);
Output:
["Version of C:hjkl.dll:", " working File Versn:", ",stopped file:", " absjhdhgh"]
To join array's elements, use:
var newString = output.join("\n"); // or <br/> instead of \n
Just match the simpler version and add an optional 2nd digit in the third group with \d?
\d\d\.\d\.\d\d?\.\d{5}
I'd use:
\b\d{2}\.\d\.\d{1,2}\.\d{5}\b
本文标签: javascriptI want the regular expression for the data of type dddddddddd or dddddddddStack Overflow
版权声明:本文标题:javascript - I want the regular expression for the data of type dd.d.dd.ddddd or dd.d.d.ddddd - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744169329a2593703.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论