paseg

paseg

Just started to use NimbleParsec, really nice!

Being a newbie I probably not understand how to best utilize it, but I really really miss a “case insensitive” option on string().

If I would like to match a word, eg "name" in a string, I would like to use the function string("name"). But if the string contains "NAME" or "Name", I will get no match.

I really need the original cases on the string, otherwise I would just use String.downcase, but this is not an option for me.

Any ideas how to best solve this?

Showing Posts 1 to 2

tmbb

tmbb

utf8_char([?n, ?N])
|> utf8_char([?a, ?A])
|> utf8_char([?m, ?M])
|> utf8_char([?e, ?E])

You can also define your own combinator (case_insensitive("name")) that returns the above.

kip

kip

ex_cldr Core Team

I came here to ask the same question and see if there was a better solution than the one I already have - which is basically the same as the one outlined by @tmbb. I created a helper combinator for it which may help others searching for the same answer. Note my version assumes ASCII input only since that fits the problem domain I am working on.

  def anycase_string(string) do
    string
    |> String.upcase
    |> String.to_charlist
    |> Enum.reverse
    |> char_piper
    |> reduce({List, :to_string, []})
  end

  defp char_piper([c]) when c in ?A..?Z do
    c
    |> both_cases
    |> ascii_char
  end

  defp char_piper([c | rest]) when c in ?A..?Z do
    rest
    |> char_piper
    |> ascii_char(both_cases(c))
  end

  defp char_piper([c]) do
    ascii_char([c])
  end

  defp char_piper([c | rest]) do
    rest
    |> char_piper
    |> ascii_char([c])
  end

  defp both_cases(c) do
    [c, c + 32]
  end
— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

CodeSync
Practical Data Orchestration in Elixir - Silvia Zeamer | ElixirConf EU 2026 https://www.youtube.com/watch?v=bVb1xmf3S34 Comments welco...
New
preciz
I like to find performance optimizations and hidden bugs in Elixir codebases with coding agents. If I just ask them directly to find tho...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews