Pages: 1
RSS
Text Replacement Macros, How do the work?
 
Greetings!

To date, https://www.ritlabs.com/en/support/help/73/ holds incomplete descriptions for the text replacement macros.

The Bat! technical support team states that they do provide limited support for the marcos.

Could you help me with finding the answers to the following questions, please?

%Replace( pattern, replaceWith, text)
1.1. What can be specified as pattern?
1.2. Can you share examples that fully describe all possible use cases, please?


%ReplaceRegExp( patternRegExp, replaceWith, text [, subPattNo] )
2.1. Does patternRegExp match PCRE 10.39?
2.2. Is it possible to specify in replaceWith groups (\1, \2 and others) specified in patternRegExp using round brackets?
2.3 What is indicated in subPattNo? Can you share examples that fully describe all possible use cases, please?

Thank you.
 
Before you get your hopes up, this is only a user-to-user forum.  Also, the macros that you are asking about, were only added to The Bat last year and it looks like you are the first person to ask about them in the forum. With so little documentation and no previous discussion, I'm afraid that the only way to find more information will be through trial and error.
I volunteer as a moderator to help keep the forum tidy. I do not work for Ritlabs SRL.
 
Quote
AKazak wrote:

%Replace( pattern, replaceWith, text)
1.1. What can be specified as  pattern ?
1.2. Can you share examples that fully describe all possible use cases, please?


%ReplaceRegExp( patternRegExp, replaceWith, text [, subPattNo] )
2.1. Does  patternRegExp  match PCRE 10.39?
2.2. Is it possible to specify in  replaceWith  groups (\1, \2 and others) specified in  patternRegExp  using round brackets?
2.3 What is indicated in  subPattNo ? Can you share examples that fully describe all possible use cases, please?


I have played with these macros a lot and there are my observations:

1.1. The 'pattern' should be understood as literal text that will be replaced by 'replaceWith' text in 'text' expression. Here the 'text' expression may be a literal text or a result of a macro, for example '%OText' (i.e. symbolic description of original message text). It may be also empty string, such as "".

1.2. Examples:
Code
%Replace("old", "new", "replacing 'old' by 'new'")
Result:
replacing 'new' by 'new'
Code
%Replace(".", "", "2023.01.11")
Result:
20230111


2.1. Probably not. It seems to me that The Bat! uses PCRE library ver. 6.2 with Unicode support.

2.2. / 2.3. No, the group (only single group a time) to be replaced is specified by its number given as fourth parameter 'subPattNo'. Both 'replaceWith' and 'text' parameters may be result of other macros. See what was replaced in following examples:

Code
%ReplaceRegExp("Total amount: *(\S+)", "139", "Total amount: 144.5")
Result:
139
Code
%ReplaceRegExp("(?i)([_\w\-\.\+]+@([_\w\-]+(\.[_\w\-]+)+))", "new.email@server.domain.com", "my.name@mail.domain.com")
Result:
new.email@server.domain.com
Code
%ReplaceRegExp("(?i)([_\w\-\.\+]+@([_\w\-]+(\.[_\w\-]+)+))", "newdomain.org", "my.name@mail.domain.com",2)
Result:
my.name@newdomain.org
Code
%ReplaceRegExp("(?i)([_\w\-\.\+]+@([_\w\-]+(\.[_\w\-]+)+))", ".org", "my.name@mail.domain.com",3)
Result:
my.name@mail.domain.org
Edited: Zygmunt Wereszczyński - 11 January 2023 11:42:00
 
Dear Zygmunt ,

 Thank you for sharing the experience!
 Let me digest it first and then I will continue the discussion.
 
The announcement below provide more information on the topic:
Quote
What's new in The Bat! v9.4 since v9.3.4 released on April 26, 2021?


[!] New HTML Editor
[!] Snooze function for MailTicker messages
[+] Automatic message format switch from plain text to HTML when a style is used or a picture is inserted
[+] New option to edit HTML code in the editor in the “Utilities -> Edit HTML source code” menu
[+] New HTML Table properties dialog
[+] The "Reset position" button in the settings of MailTicker
[+] Explicit option to export messages using UTF-8 in the Sorting Office
[+] New option "Display HTML-related message parts as attachments" for the message viewer
[+] %CHARSET="...." macro for text message export in the Sorting Office
[+] %Replace( pattern, replaceWith, text ) macro to automatically replace all occurrences of <pattern> with <replaceWith> in the <text>
[+] %ReplaceRegExp( patternRegExp, replaceWith, text [, subPattNo] ) macro to automatically replace all occurrences matching with <patternRegExp> with <replaceWith> in the <text> <subPattNo> is an optional parameter specifying the exact subpattern to be replaced
[+] %REGEXP( pattern, sample, subPatternNo ) macro for simplified substitution on %SetPattRegexp=...%RegexpBlindMatch=...%SubPatt=... combination
[+] (#000825) %SOURCE or %SOURCE=Charset macro to include original message source (using optional character set) into the text
[*] The focus now moves to the first occurrence when using the “Find” command in the HTML viewer
[*] The "Message -> Test filters" command is available again in the message list popup menu
[*] The "Change protocol" button is removed from the account settings
[*] The quoted text in sent HTML-messages is now stored within blockquote tags in the source code
[*] UTF-8 is now the default character set for text message export filter action
[*] Files with .MSG and .EML extensions are now treated as message/RFC822 ignoring declared MIME type
[*] "Ins ert Smiley" is replaced by "Insert Emoji"
[-] Draft flag was not se t when a non-draft message was open from the "Outbox" folder
[-] Quick reply's "Send" button was active without a text ready to be sent
[-] Ctrl+Enter and Ctrl+Shift+Enter shortcuts could not be used from Quick Reply until first editor's popup menu appearance
[-] Unexpected search box was sometimes visible in an attached message viewer
[-] Text in the "About" window was not displayed under some themes
[-] Closing the app while a picture viewer was open caused Access Violation errors
[-] (#002118) Access Violation errors when a message was printed by a filter action were fixed
[-] Loading of HTML was optimized to prevent eventual viewer crashes




Sure enough, there are some problems in the new HTML editor not resolved during this Beta cycle, but they are not considered as show stoppers and generally the new editor finally looks like a better replacement of the old one. So, we will continue collect feedback on the new editor and of course will keep on fixing problems and make improvements.
 
Ritlabs support has officially informed me that they lost contact with a programmer (software developer) responsible (in charge) for this functionality and thus cannot support this.
Do you have an idea of who he or she is?
 
Ritlabs support has officially confirmed that The Bat 10.3* use PCRE2, released in 2015, version 10.39 (https://www.pcre.org/).
 
Dear Zygmunt,

1.1-2. Got it!
1.3. Can I use regular expressions as a part of the search pattern?
Code
%Replace(pattern, replaceWith, text)

2.1. Ritlabs support has officially confirmed that The Bat 10.3* use PCRE2, released in 2015, version 10.39 (https://www.pcre.org/).
2.2-3. Got it!
2.4. Can patternRegExp and/or subPattNo parameters may result from other macros?
 
1.3. Unfortunately, these parameters must be literal text, not regular expression. Use regular expression as search pattern is allowed in another macro %ReplaceRegExp.

2.1. Thank you for information. I will check what PCRE2 options can be used in this implementation.

2.4. Yes, both parameters can be the results of other macros, but these results must be valid regular expression for patternRegExp parameter and number for subPattNo.
Pages: 1