It is possible to filter items that fits a simple condition to match strings in Julia:
y = ["1 123","2512","31 12","1225"] filter(x-> ' ' in x, y) [out]:
2-element Array{String,1}: "1 123" "31 12" But how do I get the reverse where I want to keep the items that doesn't match the condition in a filter?
This syntax isn't right:
> y = ["1 123","2512","31 12","1225"] > filter(x-> !' ' in x, y) MethodError: no method matching !(::Char) Closest candidates are: !(::Bool) at bool.jl:16 !(::BitArray{N}) at bitarray.jl:1036 !(::AbstractArray{Bool,N}) at arraymath.jl:30 ... in filter(::##93#94, ::Array{String,1}) at ./array.jl:1408 Neither is such Python-like one:
> y = ["1 123","2512","31 12","1225"] > filter(x-> ' ' not in x, y) syntax: missing comma or ) in argument list Additionally, I've also tried to use a regex:
> y = ["1 123","2512","31 12","1225"] > filter(x-> match(r"[\s]", x), y) TypeError: non-boolean (RegexMatch) used in boolean context in filter(::##95#96, ::Array{String,1}) at ./array.jl:1408 Beyond checking whether a whitespace is in string, how can I use the match() with a regex to filter out items from a list of strings?
["2512", "1225"], right?["2512", "1225"]but the question is more generic asking about how to usefilter()withmatch()conditions.