Skip to content

Instantly share code, notes, and snippets.

@tiagoefmoraes
Last active January 29, 2022 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagoefmoraes/5bfcaea5c167d6a0d8639231857a9c07 to your computer and use it in GitHub Desktop.
Save tiagoefmoraes/5bfcaea5c167d6a0d8639231857a9c07 to your computer and use it in GitHub Desktop.
Elixir regex sigil highlighting

Regex Syntax Highlight

Section

Run in Livebook

ExUnit.start(autorun: false, seed: 0)
defmodule Test do
  use ExUnit.Case

  test "~r" do
    assert "<" =~ (~r/</)
    assert "<" =~ (~r|<|)
    assert "<" =~ (~r(<))
    assert "<" =~ (~r[<])
    assert "<" =~ (~r{<})

    assert "<" =~ (~r"<") # >"
    assert "<" =~ (~r'<') # >'
    assert "<" =~ (~r<<>) # >
    assert "<\n" =~ (~r"""
    <
    """) # >"""
    assert "<\n" =~ (~r'''
    <
    ''') # >'''
  end

  test "~R" do
    assert "<" =~ (~R/</)
    assert "<" =~ (~R|<|)
    assert "<" =~ (~R(<))
    assert "<" =~ (~R[<])
    assert "<" =~ (~R{<})

    assert "<" =~ (~R"<") # >"
    assert "<" =~ (~R'<') # >'
    assert "<" =~ (~R<<>) # >
    assert "<\n" =~ (~R"""
    <
    """) # >"""
    assert "<\n" =~ (~R'''
    <
    ''') # >'''
  end
end
ExUnit.run()
..

Finished in 0.00 seconds (0.00s async, 0.00s sync)
2 tests, 0 failures

Randomized with seed 0
%{excluded: 0, failures: 0, skipped: 0, total: 2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment