I am not trying to reinvent the wheel. Just looking for a function which searches a string or string vector and returns true for each element where the match is found. This is what I tried so far.
grepl(x::String, y) = length(search(x, y)) > 0
grepl(x::Vector{String}, y) = length.(search(x, y)) .> 0
grepl(x::Vector{AbstractString}, y) = length.(search(x, y)) .> 0
Example usage:
v = string.('a':'z')
x = rand(v, 100) .* rand(v, 100) .* rand(v, 100)
grepl(convert(Vector{String}, x), "z")
Well, this would be a working example if I could get my types to work properly. Basically I could use the return to select only elements which have "z"
in them.
Just use contains
. On 0.6, you can use it directly with dot-broadcasting:
julia> contains.(["foo","bar","baz"],"ba")
3-element BitArray{1}:
false
true
true
On 0.5, you can simply wrap the second argument in an array: contains.(["foo","bar","baz"],["ba"])
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With