This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

regexp problem

Old posts that have not been replied to for several years.
r
ranny
Halfop
Posts: 49
Joined: Wed Jun 22, 2005 2:00 pm
Location: switzerland

regexp problem

Post by ranny »

Hello,
I try regexp.
I've two problems

Code: Select all

( ranny ): .tcl regexp {\bworld\b} "the world is good"
<eggy> Tcl: 0
Why not matching?

This code

Code: Select all

( ranny ):  .tcl regexp {l(?=o)} color
<eggy> Tcl: 1
it's ok
but

Code: Select all

( ranny ): .tcl regexp {(?<=l)o} color
<eggy> Tcl error: couldn't compile regular expression pattern: quantifier operand invalid
??

thx
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

\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
r
ranny
Halfop
Posts: 49
Joined: Wed Jun 22, 2005 2:00 pm
Location: switzerland

Post by ranny »

ok,

You can just tell me how is $string for match this code please(an example)

Code: Select all

regexp {\bworld\b} $string
thx
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

what do you want to match? describe with your own words, not with RE
r
ranny
Halfop
Posts: 49
Joined: Wed Jun 22, 2005 2:00 pm
Location: switzerland

Post by ranny »

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
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

regexp word.*is $str
r
ranny
Halfop
Posts: 49
Joined: Wed Jun 22, 2005 2:00 pm
Location: switzerland

Post by ranny »

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.
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

did you try seperating them using space. eg. \s
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

[regexp {(^|\s+)word($|\s+)} $str] && [regexp {(^|\s+)is($|\s+)} $str]
r
ranny
Halfop
Posts: 49
Joined: Wed Jun 22, 2005 2:00 pm
Location: switzerland

Post by ranny »

ok

Code: Select all

regexp {(^word\s|\sword\s|\sword$)} $string
it works for one word.

1/there is simpler?

2/ if i want match two words

Code: Select all

regexp {(^word1\s|\sword1\s) (\sword2\s|\sword2$)} $string
don't match?
I want match the string with "word1 word2" or "word2 word1"
thx
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

I gave you the solution, did you bother to test it at all?
r
ranny
Halfop
Posts: 49
Joined: Wed Jun 22, 2005 2:00 pm
Location: switzerland

Post by ranny »

erf,

sorry demond but we've post at the same time.Thx
r
ranny
Halfop
Posts: 49
Joined: Wed Jun 22, 2005 2:00 pm
Location: switzerland

Post by ranny »

Hello, another question,
If i want match "WOrd" or "word" or "worD"...
How to do it?
Thx
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

Code: Select all

regexp -nocase { .....
r
ranny
Halfop
Posts: 49
Joined: Wed Jun 22, 2005 2:00 pm
Location: switzerland

Post by ranny »

Ahhhh,
It's what I had done but with an error :oops:
Thx
Locked