sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor do a pattern match against a string. This is exactly the first step i needs to take for my first phoenix project.
in my project, I am receiving a ton of strings that look like:
<li>Kiwi Jr. (33)</li>
<li>Deep State (29)</li>
<li>Piroshka (29)</li>
where he did something like:
iex(1)> string = "<li>Kiwi Jr. (33)</li>"
"<li>Kiwi Jr. (33)</li>"
iex(2)> "<li>"<>artist<>"("<>playcount<>"</li>" = string
** (ArgumentError) the left argument of <> operator inside a match should be always a literal binary as its size can't be verified, got: artist
obviously, i am missing something .. I would like to end up with:
artist = Kiwi Jr.
play count = 33
anyone see where i am putting it in the ditch?
thanks!
Trending in Questions
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
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
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
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 14 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sergio_101
I ended up using Floki.. took 2.. maybe 3 seconds..
OvermindDL1
That is horrifyingly beautiful, lol! ^.^
This This This!
Using Meeseeks if you want to read it or Floki if you want to write it or something instead.
Ah the classic. ^.^
1player
Here’s some details on how to easily parse HTML with regexes:
sergio_101
SNAP! okay.. Floki looks like the jam! this can be parsed much cleaner, as there are a bazillion lines in this fie.. all LIs..
Thanks!
dimitarvp
If these are guaranteed to be small HTML pieces I’d parse them with Floki or Meeseks and then apply a simpler regex on the text to get the two pieces of data you require.
Regex for HTML or XML is a hard “NO!” even if you do a two-days educational throwaway project.
mudasobwa
You probably meant “rather than a straight regex.” Well, it depends . In most cases
Regexis just fine. Also, if you are after parsing the (contrived example) ISO8601 representation of a date, you might extractyear,monthanddaystraight away:There is no silver bullet.
sergio_101
okay.. so, my next question. is there something more “functional” about doing it this way, rather than a straight pattern match? i have spent the past 30 years in the OOP world. I used Lisp maybe 30 years ago, but didn’t know enough to really make the distinction back then.
I know I initially asked about doing it with a pattern match, just because i saw that in a course, and EVERY TIME i need to do regex, i need to look at the docs..
Thanks!
mudasobwa
Indeed. We call it Matching Dragon.
NobbZ
Close, but wrong
it generates a single function with 1001 heads.
mudasobwa
Nope. The code above generates 1001 functions handling all possible combinations of lengths for
artistandnumin the intervals1..100and1..10respectively. Plus one sink-all clause in the lengths are not in these intervals.One cannot pattern-match the binary of arbitrary length in the middle, but a match to the binary of the explicit length is allowed.