JavaScript 在列表中选择特定类型的号码
JavaScript choosing a specific type of number in a list
我正在尝试从 JavaScript 中的号码列表中选择特定类型的号码。 a Console.log(vars)
输出下面的数字列表。并且我需要选择具有 0.000 格式的数字,这意味着至少小数点前一个数字和小数点后三个数字。
(66) ['47,416.00', '0.001', '08:17:36', '47,416.00', '0.005', '08:17:36', '47,416.00', '0.088', '08:17:36', '47,416.00', '0.003', '08:17:35', '47,416.00', '0.214', '08:17:33', '47,416.00', '0.005', '08:17:33', '47,416.00', '0.008', '08:17:33', '47,416.00', '0.005', '08:17:33', '47,416.00', '0.010', '08:17:33', '47,416.00', '0.758', '08:17:33', '47,416.00', '', '0.134', '08:17:33', '47,416.50', '', '0.004', '08:17:33', '47,416.00', '0.018', '08:17:31', '47,416.00', '0.171', '08:17:30', '47,416.00', '0.034', '08:17:28', '47,416.00', '', '0.010', '08:17:28', '47,416.50', '0.003', '08:17:28', '47,416.50', '1.000', '08:17:28', '47,416.50', '0.011', '08:17:28', '47,416.50', '0.001', '08:17:25', '47,416.50', '0.005', '08:17:25']
我尝试了一个正则表达式,您可以在下面的代码中看到它,但正则表达式只返回 true
。
var tradescards = [];
let regex = /\d\.\d\d\d/;
function obser1() {
const trades = document.querySelector("#root > main > div.main-left > div.react-grid-layout > div:nth-child(3) > div > div.by-card__body > div > div");
const vars = [...trades.querySelectorAll("span")].map(span => span.textContent);
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.addedNodes.length) {
console.log(regex.test(vars));
}
})
});
observer.observe(trades, {
childList: true,
subtree: true,
attributes: true,
characterData: true
})
}
window.setTimeout(obser1, 1900);
arr.filter(e => /\d.*\.\d\d\d\b/g.test(e))
您正在寻找这样的东西。
有一个 post 解释正则表达式的工作原理。
Regex Matches - Wildcard then one decimal place
我正在尝试从 JavaScript 中的号码列表中选择特定类型的号码。 a Console.log(vars)
输出下面的数字列表。并且我需要选择具有 0.000 格式的数字,这意味着至少小数点前一个数字和小数点后三个数字。
(66) ['47,416.00', '0.001', '08:17:36', '47,416.00', '0.005', '08:17:36', '47,416.00', '0.088', '08:17:36', '47,416.00', '0.003', '08:17:35', '47,416.00', '0.214', '08:17:33', '47,416.00', '0.005', '08:17:33', '47,416.00', '0.008', '08:17:33', '47,416.00', '0.005', '08:17:33', '47,416.00', '0.010', '08:17:33', '47,416.00', '0.758', '08:17:33', '47,416.00', '', '0.134', '08:17:33', '47,416.50', '', '0.004', '08:17:33', '47,416.00', '0.018', '08:17:31', '47,416.00', '0.171', '08:17:30', '47,416.00', '0.034', '08:17:28', '47,416.00', '', '0.010', '08:17:28', '47,416.50', '0.003', '08:17:28', '47,416.50', '1.000', '08:17:28', '47,416.50', '0.011', '08:17:28', '47,416.50', '0.001', '08:17:25', '47,416.50', '0.005', '08:17:25']
我尝试了一个正则表达式,您可以在下面的代码中看到它,但正则表达式只返回 true
。
var tradescards = [];
let regex = /\d\.\d\d\d/;
function obser1() {
const trades = document.querySelector("#root > main > div.main-left > div.react-grid-layout > div:nth-child(3) > div > div.by-card__body > div > div");
const vars = [...trades.querySelectorAll("span")].map(span => span.textContent);
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.addedNodes.length) {
console.log(regex.test(vars));
}
})
});
observer.observe(trades, {
childList: true,
subtree: true,
attributes: true,
characterData: true
})
}
window.setTimeout(obser1, 1900);
arr.filter(e => /\d.*\.\d\d\d\b/g.test(e))
您正在寻找这样的东西。
有一个 post 解释正则表达式的工作原理。
Regex Matches - Wildcard then one decimal place