| View previous topic :: View next topic |
| Author |
Message |
ranny Halfop
Joined: 22 Jun 2005 Posts: 49 Location: switzerland
|
Posted: Mon Aug 15, 2005 3:17 pm Post subject: regexp problem |
|
|
Hello,
I try regexp.
I've two problems | Code: |
( ranny ): .tcl regexp {\bworld\b} "the world is good"
<eggy> Tcl: 0
|
Why not matching?
This code | Code: | ( ranny ): .tcl regexp {l(?=o)} color
<eggy> Tcl: 1
|
it's ok
but
| Code: |
( ranny ): .tcl regexp {(?<=l)o} color
<eggy> Tcl error: couldn't compile regular expression pattern: quantifier operand invalid
| ??
thx |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Mon Aug 15, 2005 3:38 pm Post subject: |
|
|
\b is RE escape for backspace and you don't have backspace
(?=re) is positive lookahead, valid in AREs (advanced REs) only, and I very much doubt it's that what you had in mind
(?<= is RE error |
|
| Back to top |
|
 |
ranny Halfop
Joined: 22 Jun 2005 Posts: 49 Location: switzerland
|
Posted: Mon Aug 15, 2005 4:57 pm Post subject: |
|
|
ok,
You can just tell me how is $string for match this code please(an example)
| Code: | | regexp {\bworld\b} $string |
thx |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Mon Aug 15, 2005 5:01 pm Post subject: |
|
|
| what do you want to match? describe with your own words, not with RE |
|
| Back to top |
|
 |
ranny Halfop
Joined: 22 Jun 2005 Posts: 49 Location: switzerland
|
Posted: Tue Aug 16, 2005 2:07 am Post subject: |
|
|
Yes, i try with an example.
I want to match a string(with regexp) who contains the words "word" and "is".
In fact i don't want to match a word who contains the words.
"the word is simple"==>match
"this word "==>not match
"F**** is a badword"==>not match
......
thx |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Aug 16, 2005 2:38 am Post subject: |
|
|
| Code: |
regexp word.*is $str
|
|
|
| Back to top |
|
 |
ranny Halfop
Joined: 22 Jun 2005 Posts: 49 Location: switzerland
|
Posted: Tue Aug 16, 2005 7:23 am Post subject: |
|
|
no demond,
it's not that.
I want that the code matches all string with "word" and "is". But it shouldn't match the words who contains "word" and "is"(badword,this,history...don't have matches).
I thought that to use \b was a solution to limit the word but it's not that.
If you can help me. |
|
| Back to top |
|
 |
greenbear Owner
Joined: 24 Sep 2001 Posts: 733 Location: Norway
|
Posted: Tue Aug 16, 2005 9:37 am Post subject: |
|
|
| did you try seperating them using space. eg. \s |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Aug 16, 2005 11:54 am Post subject: |
|
|
| Code: |
[regexp {(^|\s+)word($|\s+)} $str] && [regexp {(^|\s+)is($|\s+)} $str]
|
|
|
| Back to top |
|
 |
ranny Halfop
Joined: 22 Jun 2005 Posts: 49 Location: switzerland
|
Posted: Tue Aug 16, 2005 11:59 am Post subject: |
|
|
ok | Code: | | regexp {(^word\s|\sword\s|\sword$)} $string |
it works for one word.
1/there is simpler?
2/ if i want match two words | Code: | | regexp {(^word1\s|\sword1\s) (\sword2\s|\sword2$)} $string |
don't match?
I want match the string with "word1 word2" or "word2 word1"
thx |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Aug 16, 2005 12:14 pm Post subject: |
|
|
| I gave you the solution, did you bother to test it at all? |
|
| Back to top |
|
 |
ranny Halfop
Joined: 22 Jun 2005 Posts: 49 Location: switzerland
|
Posted: Tue Aug 16, 2005 5:00 pm Post subject: |
|
|
erf,
sorry demond but we've post at the same time.Thx |
|
| Back to top |
|
 |
ranny Halfop
Joined: 22 Jun 2005 Posts: 49 Location: switzerland
|
Posted: Thu Aug 18, 2005 7:15 am Post subject: |
|
|
Hello, another question,
If i want match "WOrd" or "word" or "worD"...
How to do it?
Thx |
|
| Back to top |
|
 |
greenbear Owner
Joined: 24 Sep 2001 Posts: 733 Location: Norway
|
Posted: Thu Aug 18, 2005 10:52 am Post subject: |
|
|
| Code: | | regexp -nocase { ..... |
|
|
| Back to top |
|
 |
ranny Halfop
Joined: 22 Jun 2005 Posts: 49 Location: switzerland
|
Posted: Thu Aug 18, 2005 1:23 pm Post subject: |
|
|
Ahhhh,
It's what I had done but with an error
Thx |
|
| Back to top |
|
 |
|