tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,7 @@
|
|||
#load "str.cma";;
|
||||
let str = "I am a string";;
|
||||
try
|
||||
ignore(Str.search_forward (Str.regexp ".*string$") str 0);
|
||||
print_endline "ends with 'string'"
|
||||
with Not_found -> ()
|
||||
;;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
#load "str.cma";;
|
||||
let orig = "I am the original string";;
|
||||
let result = Str.global_replace (Str.regexp "original") "modified" orig;;
|
||||
(* result is now "I am the modified string" *)
|
||||
10
Task/Regular-expressions/OCaml/regular-expressions-3.ocaml
Normal file
10
Task/Regular-expressions/OCaml/regular-expressions-3.ocaml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
let matched pat str =
|
||||
try ignore(Pcre.exec ~pat str); (true)
|
||||
with Not_found -> (false)
|
||||
;;
|
||||
|
||||
let () =
|
||||
Printf.printf "matched = %b\n" (matched "string$" "I am a string");
|
||||
Printf.printf "Substitute: %s\n"
|
||||
(Pcre.replace ~pat:"original" ~templ:"modified" "I am the original string")
|
||||
;;
|
||||
Loading…
Add table
Add a link
Reference in a new issue