String comparison by template, something like str=="us*", where * is mean any symbol

Would somebody suggest:
string comparison by template, something like str==“us*”, where * is mean any symbol

thanks

1 Like

regex? http://julia.cookbook.tips/doku.php?id=regex

3 Likes
julia> occursin(r"^us.*", "usage")
true

julia> occursin(r"^us.*", "bus")
false
1 Like

thanks =)

Just FYI, if you’re only interested in strings that start with "us", there’s a specialized function on string for that:

julia> startswith("usage", "us")
true

I only mention it, because this approach is faster than a regexp match for this limited case (though, obviously not as flexible).

3 Likes