["9.358,26 €", "Hello World", "3.562,77 €", "3,77 €"] -> ["Hello World"]
I was thinking of using regex, but is there a more easy way?
["9.358,26 €", "Hello World", "3.562,77 €", "3,77 €"] -> ["Hello World"]
I was thinking of using regex, but is there a more easy way?
Assuming this is Python, a simple List Comprehension should suffice:
lst = ["9.358,26 €", "Hello World", "3.562,77 €", "3,77 €"]
[el for el in lst if "€" not in el]
>>> ["Hello World"]
Another option is using the filter() function:
def contains_currency(s):
return "€" not in s
list(filter(contains_currency, lst))
more compactly using an anonymous function:
list(filter(lambda s: "€" not in s, lst))
Assuming this is Javascript, a simple filter() should suffice:
let array = ["9.358,26 €", "Hello World", "3.562,77 €", "3,77 €"];
filteredArray = array.filter((item) => !item.includes('€'));
console.log(filteredArray);
// ["Hello World"]
Read more about the includes()
method here.