Skip to content

Instantly share code, notes, and snippets.

@theqp
Last active November 27, 2020 02:56
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 theqp/8d38a3997deb3f15f17b1b5be1e996a9 to your computer and use it in GitHub Desktop.
Save theqp/8d38a3997deb3f15f17b1b5be1e996a9 to your computer and use it in GitHub Desktop.
module RegexReadPrice where
import qualified Data.ByteString.Lazy.Char8 as C
import Data.Function ((&))
import GHC.Arr (Array, elems)
import Text.Regex.TDFA (MatchText, getAllTextMatches, (=~))
-- >>> matches (C.pack "1.01")
-- []
matches :: C.ByteString -> [MatchText C.ByteString]
matches s =
(getAllTextMatches (s =~ "(\\d+)\\D(\\d{2})") :: Array Int (MatchText C.ByteString))
& elems
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment