Skip to main content

Ralsina.Me — Roberto Alsina's website

Any regex wizard reading this?

If so, what is the C POSIX regex (y­ou know reg­comp & friend­s) equiv­a­lent of this python reg­u­lar ex­pre­sion:

re.compile(r'^([a-z][a-z0-9_\-\.]*)=', re.IGNORECASE)

Be­cause it sure is­n't this:

regcomp(&re,"^([a-z][a-z0-9_\-\.]*)=",REG_ICASE)

I have been play­ing with it for two hours and am bored :-)

sebr / 2007-02-13 03:50:

Me, no idea, but you .htaccess files are messed up, since the post permalink redirects to your host 404 page.

Albert Astals Cid / 2007-02-13 07:59:

not sure, but maybe you need to convert -> \

jml / 2007-02-13 08:31:

Try regcomp(&re, "^\([a-z][a-z0-9_\-\.]*\)=", REG_ICASE);

or:

regcomp(&re, "^([a-z][a-z0-9_\-\.]*)=", REG_ICASE | REG_EXTENDED);

jml / 2007-02-13 08:33:

Some slashes disappeared in my comment. Imagine there's two slashes for every one there.

Ralesk / 2007-02-13 08:48:

I vote for the double backslash too -- think of the same reason why python needs two of them unless you're using raw strings. (what is backslash-n for C? :) surely you'd mean matching on a literal backslash-n not insert a newline in your regex)

Roberto Alsina / 2007-02-13 11:19:

Just escaping the backslashes is not enough.

regcomp(&re,"^([a-z][a-z0-9_\-\.]*)=",REG_ICASE)

doesn't even compile:

/home/ralsina/Desktop/proyectos/qmail/ra-plugins/svn/raspf/raspf.c:235:32: warning: unknown escape sequence '-'
/home/ralsina/Desktop/proyectos/qmail/ra-plugins/svn/raspf/raspf.c:235:32: warning: unknown escape sequence '.'

My best effort so far is

regcomp(&re,"^([a-z][-a-z0-9_.]*)=",REG_ICASE)

Which seems to work.

Remember these are **not** perl/python regexps :-P

Roberto Alsina / 2007-02-13 11:24:

Ok, never mind, I shouldn't try to code at 7AM :-)

Yes, the double backslashes are the thing.


Contents © 2000-2024 Roberto Alsina