Page 1 of 1

Highlighting all words that start with the same two letters

Posted: Mon Dec 01, 2003 11:54 pm
by MachineSMMC
I would like to know if it is possible to have textpad highlight all words that start with the same two letters. I am currently working with a new CAD/CAM system. They have a great macro program in it but now editor. I was hoping to get textpad to work with it much like it works with AutoLisp.

Thanks For any input.

Posted: Tue Dec 02, 2003 12:40 am
by Bob Hansen
TextPad does not allow multiple selections. And you cannot easily color or bold those choices. And I don't think you can make keywords for the syntax file that uses wildcards or RegEx.
But let me offer 3 options: 1-Mark all lines, 2-use a word processor and macro program, 3-treat as an HTML document.
Note: Using underscore "_" in following examples to represent space character for display purposes.
========================
Option 1- Mark all lines

Go to beginning of document.
Open Find window.
Find using RegEX for "space, LETTER_A, LETTER_B, one_or_more_of_any alpha-numberic_characters.:_AB[a-zA-Z0-9]+
Click on Mark All.
========================
Option 2 - Word processor and macro program

If you could make bold or color, you could do the following:
Make a macro to do the following:

Make a hot key to Select Word
Go to beginning of document.
Find using RegEX for "space, LETTER_A, LETTER_B, one_or_more_of_any alpha-numberic_characters.:_AB[a-zA-Z0-9]+Close Find window and go to that word on the document.
Press left arrow, right arrow to start at beginning of word.
Press SelectWord hot key
Apply color/font as desired.
Repeat macro to end of file.
- - - - - - - - - -
Even if you could bold/color, you would have trouble saving with those enhancements.

I would probably use a tool like Macro Scheduler to copy the text to a word processor document that allows formatting and then perform the same steps as noted above in the second option that uses another program with formatting.

========================
Option 3 - Treat as HTML document.
:idea: The best method might be to treat the document as HTML and add HTML code by doing a search and replace like this:
Search for:_(AB[a-zA-Z0-9]+)
Replace with: _<b>\1</b>
Now save it as an HTML document to retain bold formatting.

Posted: Tue Dec 02, 2003 4:14 pm
by MudGuard
instead of a space at the start of the Regex, I'd use \< which denotes the start of a word.

Advantage: words beginning at the start of line or immediately after punctuation are found, not only those with a space before them.

Posted: Tue Dec 02, 2003 6:57 pm
by Bob Hansen
Good catch MudGuard.
So new expressions, with a few more characters for words, are:

Search for:
(\<AB[a-zA-Z0-9'-_]+)
Replace with:
<b>\1</b>
Note that this underscore "_" is real, not for a space character.

Explanation of RegEx expressions:
RegEx Search expression:
(.....................= beginning of first tagged expression
\<..................= beginning of word
AB................. = AB
[a-zA-Z0-9'-_]..... = any alpha-numeric character or apostrophe, hyphen, underscore (other characters can be added)
+...................= one or more of previous term
)................... = end of first tagged expression

RegEx Replace expression:
<b>.............= HTML code for starting BOLD
\1................= first tagged expression
</b>...........= HTML code to end BOLD

And save as HTML.

Posted: Wed Dec 03, 2003 1:38 pm
by Kevin
Do this too:

Search for:
\n

Replace with:
<br>\n

Otherwise, everything is on one line.