Tapatalk

Question to Function list strings

Question to Function list strings

17
Basic UserBasic User
17

PostJun 24, 2025#1

Hi!

With this in my wordfile I get the list of TOOL CALL 1 and TOOL CALL 2 and so on.

How can I also get TOOL CALL "Tool1" and TOOL CALL "Test3" for example?

And on top, how can I list lines, that begin with "* -"?

Code: Select all

/TGBegin "Tool Call"
/TGFindStr = "%[0-9]+?^(TOOL?CALL?[0-9]+^)"
/TGEnd
Here an example of the file:

Code: Select all

69 ;
70 M48 ;WZ-RUECKZUG MIT RESET
71 ;
72 ;
73 * - UMFANGSFRAESER D12 L35 SD12
74 TOOL CALL "CUTTER 12" Z S10000 F3000
75 TOOL DEF "TASTER"
76 M3
77 * -   PLANEN
78 * -  A : -90GRAD ; B : 0GRAD
79 CALL LBL "NP1"
80 CYCL DEF 7.0 BEZUGSVERSCHIEBUNG
81 CYCL DEF 7.1 X+0
82 CYCL DEF 7.2 Y+0
83 CYCL DEF 7.3 Z+0
84 PLANE AXIAL A-90 B+0 TURN FMAX
Thanks :-)

6,826625
Grand MasterGrand Master
6,826625

PostJun 24, 2025#2

I suggest using the Perl instead of the legacy UltraEdit regular expression engine for searching for strings to display in the Function List view. The Perl regular expression engine is much more powerful and there are supported multiple capturing groups within a search expression. The strings found by the expressions inside the capturing groups are concatenated by UltraEdit to one string to display in the Function List with a space between the strings from the capturing groups.

Example:

Code: Select all

/TGBegin "Tool Call"
/TGFindStr = "^[0-9]+[\t ]+TOOL[\t ]+CALL[\t ]+(?:([0-9]+)|"([^"]+?)")"
/TGEnd
/TGBegin "Other"
/TGFindStr = "^[0-9]+[\t ]+\* -[\t ]+(.+)$"
/TGEnd
/Regexp Type = Perl
The first Perl regular expression results in getting displayed in the group Tool Call just the string CUTTER 12 for the posted example.

There could be also displayed in the Function List the string 74 CUTTER 12, i.e. line number a single space and the string in double quotes found in the file with the double quotes not displayed in the view. That would require just adding ( and ) around the expression matching the line number as shown below.

Code: Select all

/TGFindStr = "^([0-9]+)[\t ]+TOOL[\t ]+CALL[\t ]+(?:([0-9]+)|"([^"]+?)")"
74 TOOL CALL GUTTER 12 would be displayed in the Function List view with:

Code: Select all

/TGFindStr = "^([0-9]+)[\t ]+(TOOL)[\t ]+(CALL)[\t ]+(?:([0-9]+)|"([^"]+?)")"
The second Perl regular expression would find for the Function List for the posted example:

Code: Select all

UMFANGSFRAESER D12 L35 SD12
PLANEN
A : -90GRAD ; B : 0GRAD
Modify [0-9]+ to ([0-9]+) for getting also the line number displayed in the view.

(?:) is in Perl regular expression syntax a non-capturing group as used in the first search expression for an OR expression.

I suggest having the syntax highlighted file and the syntax highlighting wordfile opened in same instance of UltraEdit. After making a change in the syntax highlighting wordfile and saving it, switch to the syntax highlighted file, right click into the Function List view and click on context menu item Refresh function list. That triggers a new function list search with the expressions in just saved wordfile and the view is updated with the found strings.

There is in context menu of the Function List view also the menu item Sort list to get the found strings either listed in the order as found in the file or sorted in alphabetical order (not in alphanumeric order). It is most likely better having the Sort list option toggled off on listing the strings with line number in the function list.

17
Basic UserBasic User
17

PostJun 24, 2025#3

So first of all, thank you for this great support! 
I played a little bit with your suggestions, but in my file it did not work completely right.
With your first code there are only three tools in the list tool call, when I used the other ones, all tools were found, but the line number was only the last digit.
I added the whole file, perhaps you could find the problem.

Last but not least, is it possible to have lists for section "other", which are grouped like this (the difference is in the number of spaces between the * and -

30 * - MK52SHR-120
31 TOOL CALL "MK-50A-130" Z S1592 F1273
32 TOOL DEF "SHF-16A"
33 M3
34 * -   PLANEN AUF 0

should be in list like 

MK52SHR-120
   PLANEN AUF 0

and so on....
TESTTEIL_G352.h (442.35 KiB)   0

6,826625
Grand MasterGrand Master
6,826625

PostJun 25, 2025#4

Sorry, I should not write a reply late in the evening after 13 hours of work on computer. I made some mistakes.

I wrote to use ([0-9]+) for capturing the line numbers but used ([0-9])+ in two examples with the multiplier + outside the capturing group causing just one digit being captured and listed in the function list instead of the entire line number. I corrected that mistakes in my previous post.

I thought, it is possible to use an OR expression with a capturing group for the entire first expression matching the number after TOOL CALL and a second group for a part of the second expression matching just the string between the double quotes after TOOL CALL without the double quotes. That results in first capturing returning no string to UltraEdit on a TOOL CALL with a double quoted string which results in an undefined behavior of UltraEdit. The function list is weird filled in this case. It is necessary to use two search expressions, one for TOOL CALL followed by a number and another one for TOOL CALL followed by a string in double quotes.

It is just necessary to move ( of the capturing group to the left in the search expression for the function group Other to get captured also the whitespaces after * - and listed them in the function list too.

Here is the updated function string definition block for the wordfile:

Code: Select all

/TGBegin "Tool Call"
/TGFindStr = "^[0-9]+[\t ]+TOOL[\t ]+CALL[\t ]+([0-9]+)"
/TGFindStr = "^[0-9]+[\t ]+TOOL[\t ]+CALL[\t ]+"([^"]+?)""
/TGEnd
/TGBegin "Other"
/TGFindStr = "^[0-9]+[\t ]+\* -([\t ]+.+)$"
/TGEnd
/Regexp Type = Perl
The first search expression should be deleted if there is never a TOOL CALL followed by a number instead of a double quoted string in any syntax highlighted file as in this case the first expression is useless and just wastes CPU power for searching in files for a string never existing in the files.

The expressions above result in an alphabetic sorted function list for the attached file as follows:

Tool Call

Code: Select all

FASF-6A-90
GEWIBO-M6S
MK-50A-130
SHF-16A
SHF-8AL
SPIBO-5A
SPIBO-5A
SPINDELWZ-20-27
TOUCH_PROBE
VOLLRADIUSFR-12
Other

Code: Select all

   ABROLLEN (5X) KORRIGIERT
   BOHREN (5X)
   BOHREN ENTSPANEN VERS. EBENEN
   BOHREN SPANBRECHEN
   BOHREN URSPRUNG 2
   BOHRFRAESEN
   FASENFRAESEN
   FASENFRAESEN
   FASENFRAESEN
   FASENFRAESEN
   FASENFRAESEN
   FASENFRAESEN
   FASENFRAESEN
   FRAESEN: KANTEN BRECHEN
   GEWINDEBOHREN
   GEWINDEBOHREN (5X)
   GEWINDEBOHREN SPANBRECHEN
   KONTROLLPUNKTE AUF EINEM ZYLINDER
   OFFENE TASCHE
   OFFENE TASCHE (AXIAL)
   PLANEN AUF 0
   REIBEN (FUNKTIONSTEST)
   SCHRAEGE 1ACHSE HINTEN
   SCHRAEGE 2ACHSEN HINTEN
   SCHRAEGE VORN
   SCHRUPPEN INNEN
   SLI AK ZAPFEN
   SPINDELN (FUNKTIONSTEST)
   SRU ZAPFEN
   SWEEP-BEARBEITUNG
   SWEEP-BEARBEITUNG (5X)
   TASCHENRAEUMEN (RADIAL)
  B : -170GRAD ; A : 0GRAD
  B : -45GRAD ; A : -20GRAD
  B : -45GRAD ; A : -20GRAD
  B : -45GRAD ; A : -20GRAD
  B : -45GRAD ; A : 0GRAD
  B : 0GRAD ; A : -90GRAD
  B : 0GRAD ; A : -90GRAD
  B : 0GRAD ; A : -90GRAD
  B : 0GRAD ; A : -90GRAD
  B : 0GRAD ; A : -90GRAD
  B : 0GRAD ; A : -90GRAD
  B : 0GRAD ; A : -90GRAD
  B : 0GRAD ; A : -90GRAD
  B : 0GRAD ; A : -90GRAD
  B : 0GRAD ; A : -90GRAD ; FSP1-ACHSE : 0GRAD
  B : 0GRAD ; A : -95GRAD
  B : 0GRAD ; A : -95GRAD
  B : 0GRAD ; A : -95GRAD
  B : 0GRAD ; A : -95GRAD
  B : 0GRAD ; A : 0GRAD
  B : 0GRAD ; A : 0GRAD
  B : 0GRAD ; A : 0GRAD
  B : 0GRAD ; A : 0GRAD
  B : 0GRAD ; A : 0GRAD
  B : 30GRAD ; A : 0GRAD
  B : 30GRAD ; A : 0GRAD
  B : 45GRAD ; A : 0GRAD
 3D-TASTER D6
 BOHRSTANGE D5 L20 SD5
 DF-GEWINDEBOHRER M6
 DF-SCHAFTFRAESER D16
 DF-SCHAFTFRAESER D8
 DF-SPIRALBOHRER D5
 DF-SPIRALBOHRER D5
 DF-SPIRALBOHRER D5
 FASENFRAESER D6 D2=0,001 A45 L3 SD6
 KUGELFRAESER D12 L25 SD12
 LBL "NP1"
 LBL "NP2"
 MK52SHR-120

17
Basic UserBasic User
17

PostJun 26, 2025#5

Hello Mofi.

You should not say sorry, it is really awesome, what you create here and give help (I read many other topics and I cannot imagine, what other stuff you do in free time ;-)
So again thanks.

But I want more 😂.

No, I have two questions and then I think it works perfect.

First question: In the section other all lines are listed, which have the signs * - at beginning. It does not recognize the spaces after the - until the next text in it. Would this be possible?

So for example, I only want the lines with one ant three spaces ...

And second question.

Is it possible to combine the two lists Tool Call and Other in one list and a good indentation. I tried to give a example for list, I only would need the result from TOOL CALL and the string with * - and three spaces after the "-".

Code: Select all

MK-50A-130
   PLANEN AUF 0
SHF-16A
   SCHRAEGE 2ACHSEN HINTEN
SHF-8AL
   TASCHENRAEUMEN (RADIAL)
And another thing, what would be "%*^{[^}^{[^}" in Perl?

It gives me that (in picture), what is okay, but I do not understand, how it works. :-(

Thanks a lot!!!
2025-06-26_15h11_23.jpg (634.77KiB)

6,826625
Grand MasterGrand Master
6,826625

PostJun 27, 2025#6

There could be used for a hierarchical function list the following find strings definition:

Code: Select all

/TGBegin "Tool Calls"
/TGFindStr = "^[0-9]+[\t ]+TOOL[\t ]+CALL[\t ]+([0-9]+)"
/TGFindStr = "^[0-9]+[\t ]+TOOL[\t ]+CALL[\t ]+"([^\r\n"]+?)""
/TGBegin "Other"
/TGFindStr = "^[0-9]+[\t ]+\* - {3}(.+)$"
/TGFindBStart = "TOOL[\t ]+CALL"
/TGFindBEnd = "(?:TOOL[\t ]+CALL|\z)"
/TGEnd
/TGEnd
/Regexp Type = Perl
For each TOOL CALL found in the active file is searched next in the block from this TOOL CALL to either next TOOL CALL OR end of file referenced with \z for a line with a line number and * - and exactly three normal spaces and listing everything after the three spaces on these lines in the subgroup Other of the current TOOL CALL. There should be of course used a better name for the inner function strings than Other.

The function list can be sorted alphabetically or unsorted on using this function string definition.

More simple is:

Code: Select all

/TGBegin "Tool Calls"
/TGFindStr = "^[0-9]+[\t ]+TOOL[\t ]+CALL[\t ]+([0-9]+)"
/TGFindStr = "^[0-9]+[\t ]+TOOL[\t ]+CALL[\t ]+"([^\r\n"]+?)""
/TGFindStr = "^[0-9]+[\t ]+\* -( {3}.+)$"
/TGEnd
This produces a flat function list. But in this case the option Sort list must be toggled off in the context menu of the Function List view as otherwise it is not visible which string after * - and exactly three spaces belongs to which TOOL CALL block.

The UltraEdit regular expression %*^{[^}^{[^} is not good although it looks like it worked somehow for you. It means start each search at the beginning of a line, find zero or more characters except newline characters non-greedy followed by an opening square bracket OR an opening square bracket. The OR expression ^{^}^{^} makes no sense on specifying twice the same string. Another issue here is that [ is also in UltraEdit syntax the beginning of a character class definition and needs to be escaped with ^ for being interpreted as literal character. I am really wondering that you get strings in the function list displayed with that UltraEdit regular expression at all as when I run it manually from the Find and Replace dialog window, it does not find the lines as shown on the attached image at all.

There can be used in Perl syntax the following to find any string within the first pair of opening and closing square brackets on a line.

Code: Select all

/TGBegin "Squared strings"
/TGFindStr = "^[^\r\n[]*\[([^\r\n\]]+)\]"
/TGEnd
The escape character in a Unix/Perl regular expression is \ instead of ^ as in an UltraEdit regular expression. The character [ is interpreted as beginning of a character class definition, except it is escaped with \ to be interpreted literally or the opening square bracket is used inside a character class definition like the first character class definition in the search expression above. The character ] is interpreted literally by default, except a character class definition is opened where it marks the end of the character class definition.The character ] must be escaped with \ if this character should be one of the characters of the character class definition.

The expression must be read as follows:

^ … start each search at the beginning of a line.

[^] … that is a negative character class definition because of ^ after the opening square bracket beginning the character class definition to find a character which is NOT one of the characters defined next.

\r\n[ … There should be found a character which is NOT a carriage return, NOT a line feed and NOT an opening square bracket.

There is applied to the negative character class definition the multiplier * which means zero or more times (greedy which is not relevant here). So the first negative character class definition with multiplier * matches zero or more characters in a line up to either finding an opening square bracket or a new line character or reaching the end of the file.

\[ … there must be found next literally the character [ for a positive find. If there is a newline character like carriage return or line feed or the end of the file is reached, the find is negative for this line resulting in stopping the search for this line and ignoring the line without an opening square bracket.

( … begins the capturing group to define which part of the entire found string should be displayed in the function list. The opening round bracket can be moved left to \[ to get the opening square bracket also displayed in the function list as with the function string definition below.
 
[^\r\n\]]+ … is again a negative character class definition to find a character which is NOT a carriage return, NOT a line feed and NOT a closing square bracket (instead of an opening square bracket) with the multiplier + for one or more such characters. In other words a line with [] as first square brackets pair with no characters between the two square brackets is ignored as the entire expression is not positive for such a line.

) … ends the capturing group to define which part of the entire found string should be displayed in the function list. The closing round bracket can be moved right to \] to get the closing square bracket also displayed in the function list as with the function string definition below.

There must be found next ] for a positive match. A line with having just [ but no ] is ignored for that reason.

The function string definition with the square brackets also displayed in the function list is:

Code: Select all

/TGBegin "Squared strings"
/TGFindStr = "^[^\r\n[]*(\[[^\r\n\]]+\])"
/TGEnd
Well, easier to read and also working is:

Code: Select all

/TGBegin "Squared strings"
/TGFindStr = "^.*?\[(.+?)]"
/TGEnd
.*? … matches any character except newline characters zero or more times non-greedy. This expression matches also all characters (from the beginning of a line) up to first occurrence of [ specified next in the expression.

.+? … matches any character except newline characters one or more times non-greedy. This expression matches also all characters (after [) up to first occurrence of ] specified next in the expression.

The function string definition with the square brackets also displayed in the function list.

Code: Select all

/TGBegin "Squared strings"
/TGFindStr = "^.*?(\[.+?])"
/TGEnd
Which of the four variants is used is up to you. They all find the same string without or with the square brackets for the function list.

Last, a special hint: Save a screenshot showing text as PNG or WEBP image. Both are supported by web browsers and many other applications (especially PNG) and use a lossless compression producing for a screenshot nevertheless a much smaller file than the JPG image format.

17
Basic UserBasic User
17

PostJun 27, 2025#7

All your solutions give me back every line with a [...].
But as you can see in the JPEG ;-) , only the lines which directly start with [ should be in the function list.

But now the result is that:
2025-06-27_10h27_57.png (320.66KiB)

6,826625
Grand MasterGrand Master
6,826625

PostJun 27, 2025#8

Please attach a file or add to your post a code block with lines to find and also some lines to ignore. It is impossible for UltraEdit to apply a regular expression on binary data of an image. I do not want to type text manually what you have in text form but share with us in graphic form.

Hint: Replace the multiplier * by + and lines with [ at beginning of the line are ignored as now there must be other characters left to first opening square bracket. There could be inserted also , left to \[ to get a positive match only if there is a comma left to the opening square bracket on using one of the two easier expressions using .+?.

PS: DeepL can be used for free translation of text from English to German and from German to English.

17
Basic UserBasic User
17

PostJun 27, 2025#9

Here is an example file.
test.ini (11.55 KiB)   0

6,826625
Grand MasterGrand Master
6,826625

PostJun 28, 2025#10

This function string definition lists all strings in first square brackets except those at the beginning of the line.

Code: Select all

/TGBegin "Squared strings"
/TGFindStr = "^.+?(\[.+?])"
/TGEnd
/Regexp Type = Perl
This definition lists all strings in first square brackets beginning with DEFINE or MYDEFINE.

Code: Select all

/TGBegin "Defines"
/TGFindStr = "(\[(?:MY)?DEFINE.+?])"
/TGEnd
The above definition can be extended to get displayed in a second group also strings in square brackets beginning with #.

Code: Select all

/TGBegin "Defines"
/TGFindStr = "(\[(?:MY)?DEFINE.+?])"
/TGEnd
/TGBegin "Hashed strings"
/TGFindStr = "\[(#.+?)]"
/TGEnd
/Regexp Type = Perl
Here is one more definition for additionally including the groups.

Code: Select all

/TGBegin "Groups"
/TGFindStr = "^\[(.+?)]"
/TGEnd
/TGBegin "Defines"
/TGFindStr = "(\[(?:MY)?DEFINE.+?])"
/TGEnd
/TGBegin "Hashed strings"
/TGFindStr = "\[(#.+?)]"
/TGEnd
/Regexp Type = Perl

17
Basic UserBasic User
17

PostJul 07, 2025#11

So, again thank you for your explaination, it works fine for me and I hope, I can do my next adjustments with your descriptions...

PostJul 07, 2025#12

I have another little problem, I think that would be easy for you.

I have files with such a code:

Code: Select all

<<1: T21 vorladen HS OR
<N0001: ..........
<N0002: ..........
This code works good.

Code: Select all

/TGBegin "Function Oper"
/TGFindStr = "[<<][0-9]+[:]"
/TGEnd
How to change the TGFindStr, that I also can find:

Code: Select all

<<P1> 1: T21 vorladen HS OR
<N0001: .......
<N0002: .......
After the P can be different numbers (1 to 6).

I tried this, but it did not work.

Code: Select all

/TGBegin "Function Oper Channel1"
/TGFindStr = "[<<P1>][0-9]+[:]"
/TGEnd
And perhaps you have a solution for finding all lines which have "(OP:..." in it. After "OP:" are different numbers. I tried, but I do not check it. :-( I need listed the whole line.)

N2009 (-----------)
N40 (OP:5 FLUEGEL VORFRAESEN HS OR)
#607=40
N2010 (STELLRAM D20-77MM)
N2011 T21.1 T19 M06

6,826625
Grand MasterGrand Master
6,826625

PostJul 08, 2025#13

[] is a character class definition to find one of the characters defined inside the square brackets. [<<] does not make sense as it defines a character class with specifying twice the same character and means therefore find one < or one <. That is not wanted. There should be found the string <<. A character class definition with a single character like [:] makes also no sense as in this case a character class is not necessary at all. The character to find can be specified directly in the search expression without the square brackets for a character class definition. [<<P1>] is also wrong as you do not want to find one < or one < or one P or one 1 or one > but the entire string.

The solution for the function list group Function Oper is:

Code: Select all

/TGBegin "Function Oper"
/TGFindStr = "(<<(?:P[0-9]+> )?[0-9]+:.*)$"
/TGEnd
The Perl regular expression means:
  1. Find anywhere within a line a string beginning with <<.
  2. (?:) defines a non-marking group. The expression inside this non-marking group is P[0-9]+> which means to find the character P, followed by a digit in range 0 to 9 one or more times because of the multiplier + applied to the character class definition to find an entire number and not just one digit of the number, followed by the character > and a space character. There is with ? a multiplier applied on the entire non-marking group which tells the Perl regular expression engine that the expression inside the non-marking group must match after << a string either zero or one times. The multiplier ? after a non-marking group or a character class is for that reason often also name the optional multiplier because of the string or character matched by the preceding expression or character class can but must not exist in the entire matched string. In other words "P1> " or "P5832> " may optionally exist after <<.
  3. [0-9]+: matches a number with one or more digits and there must be next a colon.
  4. .*$ matches zero or more occurrences of any character except newline characters up to end of the line. $ is an anchor for end of line not matching (selecting) any character.
The entire matched string is enclosed with () in a marking group to get the entire matched string beginning from << to end of the line displayed in the function list.
The expression searches therefore for << anywhere in the file followed optionally by P and a number with one or more digits and > and a space before next must be found a number with one or more digits and a colon and matched are additionally all other characters up to end of the line.

The second wanted function string expression is:

Code: Select all

/TGBegin "Oper"
/TGFindStr = "^(.*?\(OP:.*)$"
/TGEnd
  1. ^ instructs the Perl regular expression to begin each search at the beginning of a line and not anywhere inside the file.
  2. () defines again a marking group just to get the entire found line displayed in the function list.
  3. .*? matches any character except newline character zero or more times non-greedy. In this case ? after the multiplier * (or the multiplier +) does not mean zero or one times as after a non-marking group or a character class but non-greedy matching behavior. The question mark has many different meanings in a Perl regular expression depending on what is left to the question mark. Non-greedy means that matching any characters except newline characters zero or more times should stop on first occurrence of the string which must be found next which is in this case the string (OP:. The default matching behavior of .* without ? would be to match first as much characters as possible including also multiple occurrences of (OP: which means always everything from the beginning of a line up to the end of the line as just the newline characters are not matched by . and then go back in the already matched character sequence (=line) and search for last occurrence of (OP:. The greedy matching behavior would not be optimal here as it would result in first always matching each line entirely and then search in each line back for (OP: to determine if the entire expression is positive on the line or negative as not containing (OP: at all.
  4. There must be found in the line the string (OP: whereby the opening round bracket must be escaped with a backslash to be interpreted as normal character without its special meaning in a Perl regular expression.
  5. .* matches now greedy after the string (OP: all other characters in the line up to end of the line.
The entire expression is for finding an entire line containing the string (OP: anywhere inside the line.

17
Basic UserBasic User
17

PostJul 08, 2025#14

Hi Mofi,

WOW, again many many thanks for this explanation and the code. It works wonderful and I hope, that I can use the hints for my further files, I have to manage :-)

Thanks, Dirk!

PostJul 08, 2025#15

Sorry, I have a question to this code from above:

Code: Select all

/TGBegin "Defines"
/TGFindStr = "(\[(?:MY)?DEFINE.+?])"
/TGEnd

How can get the opposite of this, that means the same rules, but only the lines without DEFINE or MYDEFINE starting? So that I get 2 lists (the one with MYDEFINE / DEFINE and all others... 

Read more posts (13 remaining)