[英]Regular expression - specific text inside brackets
I am writing a node.js app that does scraping.我正在编写一个执行抓取的 node.js 应用程序。 I need to select from a string:我需要 select 从一个字符串:
[
[17,"EUR",17.03,"False",""],
[20,"EUR",20.04,"False",""],
[23,"EUR",23.05,"False",""]
],
[
[1500,"RUB",1524.2,"False",""],
[1800,"RUB",1793.9,"False",""],
[2100,"RUB",2062.99,"False",""]
]
only [..."EUR"...] arrays but I am confused with regexp.只有 [..."EUR"...] arrays 但我对正则表达式感到困惑。
Tried \[(\\bEUR)?\]
and similar ones.试过\[(\\bEUR)?\]
和类似的。 How I should correct it?我应该如何纠正它? Thanks谢谢
UPD: to be more specific - return UPD:更具体地说-返回
[20,"EUR",20.04,"False",""]
not不是
[2100,"RUB",2062.99,"False",""]
and there are many confusing []
brackets并且有很多令人困惑的[]
括号
I'd rather use Array.filter
instead of using RegEx.我宁愿使用Array.filter
而不是使用 RegEx。 It will be more straightforward and easily understandable to use just that.仅使用它会更直接,更容易理解。
EDIT: Since currencies are grouped together, you may check just the first array:编辑:由于货币分组在一起,您可以只检查第一个数组:
Array.filter(x => x[0].includes("EUR"));
You can use filter
and some
:您可以使用filter
和some
:
const bla = [ [17, "EUR", 17.03, "False", ""], [20, "EUR", 20.04, "False", ""], [23, "EUR", 23.05, "False", ""], [1500, "RUB", 1524.2, "False", ""], [1800, "RUB", 1793.9, "False", ""], [2100, "RUB", 2062.99, "False", ""], ]; const out = bla.filter(el => el.some(nEl => nEl === 'EUR')); console.log(out);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.