Need help with "-"

Help with writing and playing macros

Need help with "-"

Postby ryanlum » Thu Sep 07, 2006 2:50 am

Hi guyz
lets say i have this line

hello my name is kim-sam-soon
from that line. how do i extract "kim-sam-soon" using a macro without selecting the whole line?

i just want that phrase.
any ideas? thx in advance
User avatar
ryanlum
Newbie
 
Posts: 4
Joined: Tue Sep 05, 2006 11:00 pm

Re: Need help with "-"

Postby Bego » Thu Sep 07, 2006 4:47 am

Hi man,

do a perl regexp search like this:

PerlReOn
Find RegExp "[a-z]*\-[a-z]*\-[a-z]*"

It looks for some SMALL letters with 2 minus signs in between.

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Need help with "-"

Postby ryanlum » Thu Sep 07, 2006 5:11 am

erm the thing is
the number of -'s is not fixed..a ny way to go around it?
User avatar
ryanlum
Newbie
 
Posts: 4
Joined: Tue Sep 05, 2006 11:00 pm

Re: Need help with "-"

Postby Bego » Thu Sep 07, 2006 6:08 am

erm, this make thinks look harder.
The problem is, that you cant say: [a-z-]+ because it also hits words without minus ....
Well, the only soultion I find looks like this and finds up to words with 4 minus signs (you can easily extend this) including the spaces before and after to identify that word as a whole. I use the "or" condition (concatenated |).
Maybe so else finds a better algorithm:

EDITED: \w as a word-character is better
(\s\w*\-\w*\s|\s\w*\-\w*\-\w*\s|\s\w*\-\w*\-\w*\-\w*\s|\s\w*\-\w*\-\w*\-\w*\-\w*\s)

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Need help with "-"

Postby ryanlum » Thu Sep 07, 2006 6:16 am

erm..
hey.. i tried it... but it looks like it cannot work.. i used this:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Find RegExp "[a-z]*\-[a-z]*\-[a-z]*"

is the syntax alright?
User avatar
ryanlum
Newbie
 
Posts: 4
Joined: Tue Sep 05, 2006 11:00 pm

Re: Need help with "-"

Postby Bego » Thu Sep 07, 2006 6:18 am

you have to explicitly say: PerlReOn instead of UnixReOff
You need UE 12, best: 12.10a, not b
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Need help with "-"

Postby ryanlum » Thu Sep 07, 2006 7:54 am

i am using the version 12.10b.. and i changed the codes to this

InsertMode
ColumnModeOff
HexOff
PerlReOn
Find RegExp "[a-z]*\-[a-z]*\-[a-z]*"

the testing code i am using is this:
Welcome to my-life-friend

but i am still not able to get it highlighted
User avatar
ryanlum
Newbie
 
Posts: 4
Joined: Tue Sep 05, 2006 11:00 pm

Re: Need help with

Postby Bego » Thu Sep 07, 2006 8:13 am

It won't work when your file ends with your example line.
You need at least one carriage-return.
Or look also here, it depends on the match-case-settings(!):
viewtopic.php?t=3575

I use 12.10a and this (multiline) example.
Try it out and report. If it does not work, its a 12.10b bug.
See in the forum for that.

[code]lalala das ist ein test-mit vielen Strichen
lalala das ist ein-test-mit vielen Strichen
lalala das ist ein-test-mit-vielen Strichen
lalala das ist ein-test-mit-vielen-Strichen[/quote]

EDIT: IT IS A 12.10b bug. Go back to a.
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Need help with "-"

Postby Mofi » Thu Sep 07, 2006 9:37 am

Forget the Perl engine with v12.10b. Use the UltraEdit engine:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Find RegExp "[a-z]+-[a-z]+-[a-z]+"

But maybe following would be better:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Find RegExp "[a-z^-]+[ ^t]++$"

This regular expression simply selects the last "word" (= string which contains only the letter A-Z, a-z or the character '-') on a line with it's trailing spaces, if the line has trailing spaces. It will not work for the last line of the file if it is not terminated with a line termination (CRLF for DOS).

See in help of UltraEdit the page about Regular Expressions which of course you should have been already done because I have already suggested to you to read the help about the Find command and at this help page there is also the link to the UltraEdit and Unix regular expressions help. Stop wasting our time because of being too lazy to read in help.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros