gpt4 book ai didi

javascript - javascript从字符串中获取特定文本

转载 作者:行者123 更新时间:2023-11-28 16:04:12 26 4
gpt4 key购买 nike

我正在使用java脚本中的字符串,例如,如果我有以下字符串:

str = "miniprofile-container http://www.linkedin.com/miniprofile?vieweeID=8573&context=anet&view"

我想要这种类型的字符串中的 ID 号“8573”。它们的长度不同,但结构与上面相同。请帮助我实现它。

我可能会使用 strcpy 函数,但它不会是通用方法

最佳答案

var str = "miniprofile-container http://www.linkedin.com/miniprofile?vieweeID=8573&context=anet&view";
var pattern = /[0-9]+/g;
var matches = str.match(pattern); //8573

演示:http://jsfiddle.net/Qex8J/

关于javascript - javascript从字符串中获取特定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15728062/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com