Name: elm-verbal-expressions
Owner: VerbalExpressions
Description: Elm Regular expressions made easy
Created: 2016-01-03 09:26:51.0
Updated: 2018-04-12 08:57:31.0
Pushed: 2018-05-18 09:44:21.0
Homepage: null
Size: 19
Language: Elm
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
VerbalExpressions is an Elm package that helps to construct difficult regular expressions.
You can see an up to date list of all ports on VerbalExpressions.github.io.
rt Regex exposing (Regex, HowMany(..))
rt VerbalExpressions exposing (..)
Create an example of how to test for correctly formed URLs
er : Regex
er =
rex
|> startOfLine
|> followedBy "http"
|> possibly "s"
|> followedBy "://"
|> possibly "www."
|> anythingBut " "
|> endOfLine
|> toRegex
Create an example URL
Me : String
Me =
ttps://www.google.com"
Use Regex.contains to determine if we have a url
result == True
lt : Bool
lt =
gex.contains tester testMe
Replace a string with another
replaced == "We have a blue house"
aced : String
aced =
rex
|> find "red"
|> toRegex
|> replace All "blue" "We have a red house"
The following table illustrates any differences between this package's function names and the canonical VerbalExpressions operator names, and explains the reason for the difference.
| Operator Name | Function Name | Reason |
|—————|—————|——–|
| then
| followedBy
| then
is a keyword in Elm, and the compiler will not allow aliasing of keywords. andThen
is typically used in this scenario, but as a result has taken on an implicit use with chainable data-types like Task
and Maybe
. followedBy
is a good synonym for the semantic meaning of the then
VerbalExpressions operator. |
| maybe
| possibly
| maybe
might cause confusion due to the existence of the core Maybe
type. |
| or
| orElse
| or
is already a built-in function for performing logical-or operations on Bool
values. It's best practice not to alias basic functions. |
Additionally, the following operators have been omitted for technical or conventional reasons.
| Operator Name | Reason |
|—————–|——–|
| br
| Elm conventions encourage a minimal API surface, and br
offers no different readability semantics from lineBreak
. |
| any
| See above for br
, as it applies to anyOf
. |
| stopAtFirst
| Elm regular expressions handle number of matches at the function-call level, with the Regex.HowMany
type, so this functionality is not supported or needed. |
| searchOneLine
| Elm's regular expressions do not support setting the "m"
flag on their internal JavaScript representations yet. |
This Elm package is based on the original Javascript VerbalExpressions library by jehna.