Re: Str module : erase double-quoted strings
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAPFanBGvaqoAYcNwceukJQ8RFNMv2doqZOVCQyeeO3hxQypJgw@mail.gmail.com> |
I would use Str.global_replace (Str.regexp "\"[^\"]*\"") "" "abc\"def\"ghi\"jk\"lm\"nop\"qr" Note that there are other Regexp libraries around. For example you should feel free to use PCRE-ocaml instead: http://mmottl.github.io/pcre-ocaml/ On Mon, Sep 28, 2015 at 9:30 AM, [email protected] [ocaml_beginners] <[email protected]> wrote: > > > I've always found the syntax of Str-regexps rather confusing. Here > is my latest headache : in a text I want to erase all double-quoted > (à la OCaml) strings. Thus, abc"def"ghi"jk"lm"nop"qr should be turned into > abcghilmqr. > Seems pretty simple, doesn't it ? > > Here is my failed attempt : > > OCaml version 4.02.1 > > # let initial_text="abc\"def\"ghi\"jk\"lm\"nop\"qr";; > val initial_text : string = "abc\"def\"ghi\"jk\"lm\"nop\"qr" > # let double_quote=Str.quote "\"";; > val double_quote : string = "\"" > # let rgxp=Str.regexp(double_quote^"."^double_quote) > ;; > val rgxp : Str.regexp = <abstr> > # let answer=Str.global_replace rgxp "" initial_text;; > val answer : string = "abc\"def\"ghi\"jk\"lm\"nop\"qr" > > > > > >