Boost logo

Boost Users :

From: office_at_[hidden]
Date: 2008-02-26 15:37:19


Hi;

I'm a newbie to regex patterns and need help in a relative simple task:
I use boost::regex with perl syntax and I have to parse user input that
provides a feature similar to the conditional formatting of cells in
OpenOffice Calc.

The string the user enters looks like this:

>=30 [fg:red] [bg:white]
or
<0.0 [fg:none] [bg:transparent]

First the user can enter an optional operator (> < <> = <= >=) followed
by a integer or floating point number. This whole term is optional so

[fg:red] [bg:white]

is also a valid expression.

The terms for color selection are partly optional, so valid expressions
are

[fg:red]
or
[bg:white]
or
[fg:red][bg:white]
or
[bg:white][fg:red]

The key words for foreground and background colors are predefined by the
software (red, green, blue, transparent, none, ...).

I tried starting with a pattern like (C++ syntax for strings)

^(?:(<|<=|>|>=|=|<>){1}((?:-|\\+)?[0-9]+(?:\\.[0-9]+|\\,[0-9]+)?))?(?:\\s*)(?:(\\[FG:(?:BLUE|RED|GREEN|BLACK|YELLOW|WHITE|CYAN|NONE)\\])|(\\[BG:(?:BLUE|RED|GREEN|BLACK|YELLOW|WHITE|CYAN)\\])|(\\[FG:(?:BBLUE|RED|GREEN|BLACK|YELLOW|WHITE|CYAN|NONE)\\])(?:\\s*)(\\[BG:(?:BLUE|RED|GREEN|BLACK|YELLOW|WHITE|CYAN)\\])){1}$

But this does not allow the [fg:][bg:] terms to be interchanged and also
when a new color or style will be added to the format class I have to
change the pattern three times. I tried backward references with no
success.

So any help is very welcome

Thanks in advance

Martin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net