Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, March 2007
Question about QRegExp


Message 1 in thread

I have a QLineEdit where I only want to enter digits with a ',' or a '-' 
character ,the first character must be a digit and a ',' or a '-' must be 
followed by a digit.

This is what I have tried and it work, but I must repeat the [,,-]\\d{0,6} 
sequence for as many times as I want to enter  ',' or '-' characters. I would 
appreciate it if someone can help me with a more elegant way of doing this.

QRegExp rx("[1-9]\\d{0,6}[,,-]\\d{0,6}[,,-]\\d{0,6}[,,-]\\d{0,6}");

In the above example one can only enter a ',' or a '-' 3 times.

--
 [ signature omitted ] 

Message 2 in thread

Hi,

Chris wrote:
> I have a QLineEdit where I only want to enter digits with a ',' or a '-' 
> character ,the first character must be a digit and a ',' or a '-' must be 
> followed by a digit.
> 
> This is what I have tried and it work, but I must repeat the [,,-]\\d{0,6} 
> sequence for as many times as I want to enter  ',' or '-' characters. I would 
> appreciate it if someone can help me with a more elegant way of doing this.
> 
> QRegExp rx("[1-9]\\d{0,6}[,,-]\\d{0,6}[,,-]\\d{0,6}[,,-]\\d{0,6}");
> 
> In the above example one can only enter a ',' or a '-' 3 times.

Make a subexpression:

[1-9](\d{0,6}[,-]){3}\d{0,6}

Tim

--
 [ signature omitted ] 

Message 3 in thread

On Tuesday 13 March 2007 15:54, Tim Dewhirst wrote:
> Hi,
>
> Chris wrote:
> > I have a QLineEdit where I only want to enter digits with a ',' or a '-'
> > character ,the first character must be a digit and a ',' or a '-' must be
> > followed by a digit.
> >
> > This is what I have tried and it work, but I must repeat the
> > [,,-]\\d{0,6} sequence for as many times as I want to enter  ',' or '-'
> > characters. I would appreciate it if someone can help me with a more
> > elegant way of doing this.
> >
> > QRegExp rx("[1-9]\\d{0,6}[,,-]\\d{0,6}[,,-]\\d{0,6}[,,-]\\d{0,6}");
> >
> > In the above example one can only enter a ',' or a '-' 3 times.
>
> Make a subexpression:
>
> [1-9](\d{0,6}[,-]){3}\d{0,6}
>
> Tim
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/

Thanks Tim. 

--
 [ signature omitted ]