Auteur: Philip Hazel Date: À: Salvatore Iovene CC: pcre-dev Sujet: Re: [pcre-dev] Problem with regex
On Tue, 11 Dec 2007, Salvatore Iovene wrote:
> I had it working with pcretest too, if the regex is:
>
> /^\*\*\*\*\s*Starting\s*FICS\s*session\s*as\s*([^*]+)\*\*\*\*$/m
>
> Although, if I give this string to pcre_compile, the C compiler will warn me
> about invalid escape sequences: \* and \s.
However, if you give that string to pcre_compile, you are not calling it
correctly. The string you should give to pcre_compile is
with the /m option specified in the options. Of course, if you define it
as a C string, you have to double the \ characters. (Otherwise you'll
get the errors you see.) So what you want is
and then feed pattern to pcre_compile, with the PCRE_OPT_MULTILINE
option.
> Notice that when I put that thing to a file, and add the regex as first line,
> and then give that file to pcretest, I get:
>
>
> pcretest foo
>
>
> (Tue,Dec11) j
> PCRE version 7.4 2007-09-21
>
> /^\*\*\*\*\s*Starting\s*FICS\s*session\s*as\s*([^*]+)\*\*\*\*$/m
> �
> No match
>
> **** Starting FICS session as iovsal ****
> ** Unknown option '*'
There's a blank line in the file. A blank line in pcretest input ends
the test, and it then tries to read another pattern. That's why you are
getting all those compile errors.