# How to use a flag in Regex()?

**URL:** <https://discourse.julialang.org/t/how-to-use-a-flag-in-regex/41917>\
**Category:** General Usage\
**Tags:** regex\
**Created:** [June 23, 2020, 7:35am UTC](https://discourse.julialang.org/t/how-to-use-a-flag-in-regex/41917 "2020-06-23T07:35:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)\
**Post date:** [June 23, 2020, 7:35am UTC](https://discourse.julialang.org/t/how-to-use-a-flag-in-regex/41917/1 "2020-06-23T07:35:53Z")

</div>

Hi,

I wan’t to use a variable interpolation and a regex flag at the same time, is it possible ? For example

```julia
julia> x="StRinG"
"StRinG"

julia> Regex("$x")
r"StRinG"

# if I wan to ignore to ignore case with a flag :

julia> Regex("$x"i)
ERROR: UndefVarError: i not defined
Stacktrace:
 [1] top-level scope at REPL[34]:1

julia> r"StRinG"i # works but no string interpolation is possible
r"StRinG"i

julia> Regex("(?i)$x") # also works in that case but the flag is part of the regex
r"(?i)StRinG"

```

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [June 23, 2020, 7:57am UTC](https://discourse.julialang.org/t/how-to-use-a-flag-in-regex/41917/2 "2020-06-23T07:57:10Z")

</div>

You can give `"i"` as the second argument to `Regex`, as the documentation indicates:

```julia
help?> Regex
search: Regex RegexMatch

  Regex(pattern[, flags])

  A type representing a regular expression. Regex objects can be used to
  match strings with match.

  Regex objects can be created using the @r_str string macro. The
  Regex(pattern[, flags]) constructor is usually used if the pattern string
  needs to be interpolated. See the documentation of the string macro for
  details on flags.

julia> Regex("StRinG", "i")
r"StRinG"i

```

---

<div class="post-metadata">

**Author:** ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)\
**Post date:** [June 23, 2020, 8:38am UTC](https://discourse.julialang.org/t/how-to-use-a-flag-in-regex/41917/3 "2020-06-23T08:38:24Z")

</div>

Thank you @pfitzseb ! I read the documentation [here](https://docs.julialang.org/en/v1/manual/strings/index.html) and this second argument was only mentioned for r" ".
