Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

An Elixir Library to run several regular expressions on a string and get values back.

License

NotificationsYou must be signed in to change notification settings

jnylen/string-matcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This library allows you to pass multiple regular expressions and a string and get values back.

Example

Let's say you have a text that is:

Del 5 av 6. Shakespeare är mycket nöjd med sin senaste pjäs, Så tuktas en argbigga. Men av någon anledning uppskattas inte berättelsen om hur en stark kvinna förnedras av en man av kvinnorna i Shakespeares närhet.Originaltitel: Upstart Crow.Produktion: BBC 2017.

First we would split the text into an array based on\n and. so that we can loop over the long text, as our matches only returns the first match back.

Then you would do:

StringMatcher.new()|>StringMatcher.add_regexp(~r/Del\s+(?<episode_num>[0-9]+?)\s+av\s+(?<of_episodes>[0-9]+?)/i,%{})|>StringMatcher.add_regexp(~r/Originaltitel: (?<original_title>.*)\./i,%{})|>StringMatcher.add_regexp(~r/Produktion: (?<production_company>.*?) (?<production_year>[0-9]+)\./i,%{})|>StringMatcher.match_captures(string)

This should return a tuple with a map. The map is returned value of the regular expressions.If no match is found you will receive{:error, "no match"}

Installation

Ifavailable in Hex, the package can be installedby addingstring_matcher to your list of dependencies inmix.exs:

defdepsdo[{:string_matcher,"~> 0.1.0"}]end

Documentation can be generated withExDocand published onHexDocs. Once published, the docs canbe found athttps://hexdocs.pm/string_matcher.

Tests

Currently the tests are failing for some reason, the library is working though and is stable.It's used in production.

About

An Elixir Library to run several regular expressions on a string and get values back.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp