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

**URL:** <https://discourse.julialang.org/t/string-comparison-by-template-something-like-str-us-where-is-mean-any-symbol/33455>\
**Category:** New to Julia\
**Tags:** strings\
**Created:** [January 16, 2020, 8:58pm UTC](https://discourse.julialang.org/t/string-comparison-by-template-something-like-str-us-where-is-mean-any-symbol/33455 "2020-01-16T20:58:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [January 16, 2020, 8:58pm UTC](https://discourse.julialang.org/t/string-comparison-by-template-something-like-str-us-where-is-mean-any-symbol/33455/1 "2020-01-16T20:58:58Z")

</div>

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

thanks

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [January 16, 2020, 9:18pm UTC](https://discourse.julialang.org/t/string-comparison-by-template-something-like-str-us-where-is-mean-any-symbol/33455/2 "2020-01-16T21:18:38Z")

</div>

> [@BMval](#):
>
> by template,

regex? [http://julia.cookbook.tips/doku.php?id=regex](http://julia.cookbook.tips/doku.php?id=regex)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 16, 2020, 11:21pm UTC](https://discourse.julialang.org/t/string-comparison-by-template-something-like-str-us-where-is-mean-any-symbol/33455/3 "2020-01-16T23:21:36Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [January 16, 2020, 11:34pm UTC](https://discourse.julialang.org/t/string-comparison-by-template-something-like-str-us-where-is-mean-any-symbol/33455/4 "2020-01-16T23:34:25Z")

</div>

thanks =)

---

<div class="post-metadata">

**Author:** ![jballanc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jballanc/32/328_2.png) [@jballanc](https://discourse.julialang.org/u/jballanc)\
**Post date:** [January 18, 2020, 4:28pm UTC](https://discourse.julialang.org/t/string-comparison-by-template-something-like-str-us-where-is-mean-any-symbol/33455/5 "2020-01-18T16:28:14Z")

</div>

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

```julia
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).
