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 slash

Help for those learning Tcl or writing their own scripts.
Post Reply
E
Elfriede
Halfop
Posts: 67
Joined: Tue Aug 07, 2007 4:21 am

regexp slash

Post by Elfriede »

Hi everyone :)

Im afraid its quite easy, but i dont get it.

Example:

.this/is/some/text/in/here

All i need is always getting except the text after the last /
In this case -> .this/is/some/text/in

Thanks
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Personally, I'd probably consider using the "file dirname" command since you're talking of the directory separator (/), or in a more generic case, a split/lrange/join combo.

A regular expression however, would look something like this:

Code: Select all

^(.*)/[^^]+$
Implementing this in tcl would look something like this:

Code: Select all

set string ".this/is/some/text/in/here"
set pattern {^(.*)/[^^]+$}
regexp -- $pattern $string Match subMatch1
#You'll now find "./this/is/some/text/in" in the $subMatch1 variable, if we've got a match...
NML_375
E
Elfriede
Halfop
Posts: 67
Joined: Tue Aug 07, 2007 4:21 am

Post by Elfriede »

Perfect ! Exactly what i was looking for. Many, many thanks
Post Reply