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

Qt-interest Archive, July 2006
QRegExp


Message 1 in thread

question:
 
 why QRegExp("/\\*.*\\*/") has no effects ?

Message 2 in thread

On Friday 28 July 2006 10:33 am, Carabut Nicolae wrote:
> question:
>
>  why QRegExp("/\\*.*\\*/") has no effects ?

How do you mean no effect?

I can tell you it almost certainly doesn't do what you think it should do.
What you have is equivalent to QRegExp("/.*/")

What were you trying to match?


Julian.

-- 
 [ signature omitted ] 

Message 3 in thread

yes, sorry. 
 
 I'm trying to match this:
 /*************************
     some remarks
 *************************/
 
 this:
 /*
 *
 *       Some other remarks
 *
 */
 
 and everyhting else that is inside "/*"   and    "*/"

 as I understand:
 QRegExp("/\\*") gives me first match "/*"
 QRegExp("\\*/") gives me the second match "*/"
 
 and the QRegExp(".*") - matches everything including the new lines symbols.
 
 
 
----- Original Message ----
From: Julian Peterson <weaver@xxxxxxxxxx>
To: qt-interest@xxxxxxxxxxxxx
Sent: Friday, July 28, 2006 8:23:12 AM
Subject: Re: QRegExp

On Friday 28 July 2006 10:33 am, Carabut Nicolae wrote:
> question:
>
>  why QRegExp("/\\*.*\\*/") has no effects ?

How do you mean no effect?

I can tell you it almost certainly doesn't do what you think it should do.
What you have is equivalent to QRegExp("/.*/")

What were you trying to match?


Julian.

-- 
 [ signature omitted ] 

Message 4 in thread

Von: Carabut Nicolae <carabutnicolae@xxxxxxxxx>
> yes, sorry. 
>  
>  I'm trying to match this:
>  /*************************
>      some remarks
>  *************************/
>  
>  this:
>  /*
>  *
>  *       Some other remarks
>  *
>  */
>  
>  and everyhting else that is inside "/*"   and    "*/"
> 
>  as I understand:
>  QRegExp("/\\*") gives me first match "/*"
>  QRegExp("\\*/") gives me the second match "*/"
>  
>  and the QRegExp(".*") - matches everything including the new lines
> symbols.
>  
>  
Your RegExp is wrong --> at least "\\" needs to be "\\\\"
See bottom of this chapter:
http://doc.trolltech.com/4.1/qregexp#characters-and-abbreviations-for-sets-of-characters

Christian
-- 
 [ signature omitted ] 

Message 5 in thread

On Friday 28 July 2006 7:43 pm, Christian Ehrlicher wrote:
> Von: Carabut Nicolae <carabutnicolae@xxxxxxxxx>
>
> > yes, sorry.
> >
> >  I'm trying to match this:
> >  /*************************
> >      some remarks
> >  *************************/
> >
> >  this:
> >  /*
> >  *
> >  *       Some other remarks
> >  *
> >  */
> >
> >  and everyhting else that is inside "/*"   and    "*/"
> >
> >  as I understand:
> >  QRegExp("/\\*") gives me first match "/*"
> >  QRegExp("\\*/") gives me the second match "*/"
> >
> >  and the QRegExp(".*") - matches everything including the new lines
> > symbols.
>
> Your RegExp is wrong --> at least "\\" needs to be "\\\\"

No, he's right.

I made the same assumption the first time too.  He wants to match a 
literal * once rather than a \ zero or more times

Julian.

-- 
 [ signature omitted ] 

Message 6 in thread

> Von: Carabut Nicolae <carabutnicolae@xxxxxxxxx>
> > yes, sorry. 
> >  
> >  I'm trying to match this:
> >  /*************************
> >      some remarks
> >  *************************/
> >  
> >  this:
> >  /*
> >  *
> >  *       Some other remarks
> >  *
> >  */
> >  
> >  and everyhting else that is inside "/*"   and    "*/"
> > 
> >  as I understand:
> >  QRegExp("/\\*") gives me first match "/*"
> >  QRegExp("\\*/") gives me the second match "*/"
> >  
> >  and the QRegExp(".*") - matches everything including the new lines
> > symbols.
> >  
> >  
> Your RegExp is wrong --> at least "\\" needs to be "\\\\"
> See bottom of this chapter:
> http://doc.trolltech.com/4.1/qregexp#characters-and-abbreviations-for-sets-of-characters
> 
Ignore my post - it's friday and I really need the weekend ;)

Christian
-- 
 [ signature omitted ] 

Message 7 in thread

On Friday 28 July 2006 7:18 pm, Carabut Nicolae wrote:
> yes, sorry.
>
>  I'm trying to match this:
>  /*************************
>      some remarks
>  *************************/
>
>  this:
>  /*
>  *
>  *       Some other remarks
>  *
>  */
>
>  and everyhting else that is inside "/*"   and    "*/"
>
>  as I understand:
>  QRegExp("/\\*") gives me first match "/*"
>  QRegExp("\\*/") gives me the second match "*/"
>
>  and the QRegExp(".*") - matches everything including the new lines
> symbols.
>

Whoops, you are indeed correct.  Sorry, confused myself.

How are you using it?

The following gives me a correct answer:

  QRegExp r("/\\*.*\\*/");
  QString s(" one sdfhsdkjf /* ra blah\n */ dhfggsdhf\n");
  int pos = r.search( s, 0 );
  cout << "found at " << pos << " length " << r.matchedLength() << endl;

found at 15 length 14

 
Julian.

-- 
 [ signature omitted ] 

Message 8 in thread

thanks, for help.
 I will recheck my tests.

----- Original Message ----
From: Julian Peterson <weaver@xxxxxxxxxx>
To: qt-interest@xxxxxxxxxxxxx
Sent: Friday, July 28, 2006 10:52:45 AM
Subject: Re: QRegExp

On Friday 28 July 2006 7:18 pm, Carabut Nicolae wrote:
> yes, sorry.
>
>  I'm trying to match this:
>  /*************************
>      some remarks
>  *************************/
>
>  this:
>  /*
>  *
>  *       Some other remarks
>  *
>  */
>
>  and everyhting else that is inside "/*"   and    "*/"
>
>  as I understand:
>  QRegExp("/\\*") gives me first match "/*"
>  QRegExp("\\*/") gives me the second match "*/"
>
>  and the QRegExp(".*") - matches everything including the new lines
> symbols.
>

Whoops, you are indeed correct.  Sorry, confused myself.

How are you using it?

The following gives me a correct answer:

  QRegExp r("/\\*.*\\*/");
  QString s(" one sdfhsdkjf /* ra blah\n */ dhfggsdhf\n");
  int pos = r.search( s, 0 );
  cout << "found at " << pos << " length " << r.matchedLength() << endl;

found at 15 length 14

 
Julian.

-- 
 [ signature omitted ] 

Message 9 in thread

What is the frequency of white light?

 

Please give an example of what you mean... Code usually helps....

 

Also, I usually will do the following, since QRegExp is very picky WRT
escape characters...

 

QRegExp regEx( "......" );

Q_ASSERT( regEx.isValid() );

 

Just to make sure I didn't have a typo...

 

Scott

 

 

________________________________

From: Carabut Nicolae [mailto:carabutnicolae@xxxxxxxxx] 
Sent: Thursday, July 27, 2006 3:33 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: QRegExp

 

question:

why QRegExp("/\\*.*\\*/") has no effects ?


Message 10 in thread

Hi all,

I am fairly new to QRegExp. I have the following:

QRegExp rx ("\\d{1,6}\\.?}\\d{1,6}");

This matches 1-6 digits, followed by a optional decimal point, followed
by 1 to 6 decimals.


What i *actually* want to achieve is this:

If there are 6 or more digits *before* the decimal point, then only 3
digits *after* the decimal point are allowed. If there are less than 6
digits
before the decimal point, then 6 digits after the decimal point are allowed.

Is this possible with regular expressions? Maybe with back references?


Best regards,


Andre

--
 [ signature omitted ] 

Message 11 in thread

Andre Haupt wrote:
>
> Hi all,
>
> I am fairly new to QRegExp. I have the following:
>
> QRegExp rx ("\\d{1,6}\\.?}\\d{1,6}");
>
> This matches 1-6 digits, followed by a optional decimal point, followed
> by 1 to 6 decimals.
>
>
> What i *actually* want to achieve is this:
>
> If there are 6 or more digits *before* the decimal point, then only 3
> digits *after* the decimal point are allowed. If there are less than 6
> digits
> before the decimal point, then 6 digits after the decimal point are
> allowed.
>
> Is this possible with regular expressions? Maybe with back references?
>
Nevermind, I was trapped in this backreference thing that i didnt see
the obvious.
I solved this by.

QRegExp rx("(\\d{1,3}\\.}\\d{1,6})|(\\d{1,6}\\.}\\d{1,3})|(\\d{1,10})");


Best,

Andre

--
 [ signature omitted ]