-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexamples.hs
32 lines (26 loc) · 964 Bytes
/
examples.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import Text.Regex.VerbalExpressions
import Control.Arrow
main :: IO()
main = do
--create an example of how to test for correctly formed URLs
let expr = searchGlobal >>>
startOfLine >>>
find "http" >>>
possibly "s" >>>
find "://" >>>
possibly "www" >>>
anythingBut " " >>>
endOfLine
$ verEx
-- Use VerEx's test function to find if it matches
print $ test "http://www.google.com" expr
--Ouputs the actual expression used: ^(?:http)(?:s)?(?:://)(?:www.)?(?:[^ ]*)$
print $ expr
-- Create a test string
let replaceMe = "Replace bird with a duck"
-- Create an expression that seeks for word "bird"
let expr2 = find "bird" $ verEx;
-- Execute the expression
print $ replace replaceMe "duck" expr2
-- Shorthand string replace
print $ replace "We have a red house" "blue" . find "red" $ verEx