In [24]:
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString as B
import Text.Regex.TDFA.ByteString
import Text.Regex.Base.RegexLike
import Data.Array

In [9]:
:t defaultCompOpt


defaultCompOpt :: forall regex compOpt execOpt. RegexOptions regex compOpt execOpt => compOpt

In [10]:
:t compile


compile :: CompOption -> ExecOption -> ByteString -> Either String Regex

In [27]:
extractPropertyName :: B.ByteString -> B.ByteString

extractPropertyName prop_name = 
    case match of 
        Right (Just arr)  -> subset $ arr ! 1
           
        Left _ -> prop_name
  where
    rg = compile defaultCompOpt defaultExecOpt "_([a-zA-Z0-9]+)_([A-Z]+)"
    g  = case rg of 
       Left err -> error err
       Right x -> x 
    match = execute g prop_name
    subset (start,len) = B.take len . B.drop start $ prop_name

In [28]:
extractPropertyName "_helloWorld_SOMEENUM"


"helloWorld"

In [ ]: