Skip to content

Instantly share code, notes, and snippets.

@andyarvanitis
Last active April 17, 2018 03:16
Show Gist options
  • Save andyarvanitis/1d0a325a6cdb90134934685c140e02d5 to your computer and use it in GitHub Desktop.
Save andyarvanitis/1d0a325a6cdb90134934685c140e02d5 to your computer and use it in GitHub Desktop.
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log, logShow)
import Data.Either (Either(..))
import Data.Tuple (Tuple)
foreign import data PCREOption :: *
foreign import data PCRECode :: *
foreign import caseless :: PCREOption
foreign import dotall :: PCREOption
foreign import compile :: String -> Array PCREOption -> Either String PCRECode
foreign import capturedCount :: PCRECode -> Int
foreign import exec :: PCRECode ->
String ->
Int ->
Array PCREOption ->
Int ->
Either Int (Array (Tuple Int Int))
main :: forall e. Eff ( console :: CONSOLE | e ) Unit
main = do
case (compile "^([^!]+)!(.+)=apquxz\\.ixr\\.zzz\\.ac\\.uk$" [caseless]) of
Left err -> log err
Right pcre -> do
let sz = (capturedCount pcre + 1) * 3
result = exec pcre "abc!pqr=apquxz.ixr.zzz.ac.uk" 0 [] sz
logShow result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment