1

["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?

2 Answers2

1

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))
2080
  • 1,223
  • 1
  • 14
  • 37
1

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.

ChenBr
  • 1,671
  • 1
  • 7
  • 21