Text replace in web forms ( HOW TO TRIGGER )

User-to-User discussion about the PhraseExpress macro programming.
Post Reply
cybmatrix
Posts: 9
Joined: 12 Mar 19, 18:42

Text replace in web forms ( HOW TO TRIGGER )

Post by cybmatrix » 13 Mar 19, 00:43

Hi there.
I'd like to create some rules about text replace, in particular when editing pre-compiled forms for example, during web browsing.

Image

In this case, phraseexpress should trigger words like *Materiali* and automatically replace with *MATERIALS* for example.
Is this possible in some way ?

Technical Support
Posts: 2146
Joined: 10 Feb 06, 22:23

Post by Technical Support » 13 Mar 19, 09:38

This is the main function of PhraseExpress. Set Autotext to "materiali" and phrase text to "MATERIALS" and it should do exactly what asked for.

cybmatrix
Posts: 9
Joined: 12 Mar 19, 18:42

Post by cybmatrix » 13 Mar 19, 10:58

But this is a PRECOMPILED form.
So text would be already there when i open the webpage.

Is there a way to let work PE also in this condition and trigger the same "black list words" ?

Technical Support
Posts: 2146
Joined: 10 Feb 06, 22:23

Post by Technical Support » 13 Mar 19, 11:04

In this case you could copy the form content to clipboard, replace the words from the text in clipboard using macros and insert it back into the form, but it will only work with unformatted content.

cybmatrix
Posts: 9
Joined: 12 Mar 19, 18:42

Post by cybmatrix » 13 Mar 19, 12:11

Great ... so I've to create macros that work with the clipboard content.
Is there a tutorial for this ?

Peter Stotz
PhraseExpress Expert
Posts: 761
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 13 Mar 19, 13:15

@cybmatrix
Example: Mark this text:
(+) Materiali discreti
(+) Assicura ottime prestazioni
(+) Buon livello di schermatura
(+) Tante misure da scegliere nelle colorazioni nero e bianco

Then execute this macro (note: the #replace-macros are nested and case sensitive !):
{#clipboard -copy}{#setclipboard {#replace {#replace {#replace {#insertclipboard} -oldtext + -newtext *} -oldtext Materiali -newtext AAA} -oldtext bianco -newtext BBB}}

With CTRL+v you'll get this:
(*) AAA discreti
(*) Assicura ottime prestazioni
(*) Buon livello di schermatura
(*) Tante misure da scegliere nelle colorazioni nero e BBB

Manuals see here https://www.phraseexpress.com/manuals.htm
Peter
Windows 10 - PhraseExpress v14.0.131

cybmatrix
Posts: 9
Joined: 12 Mar 19, 18:42

Post by cybmatrix » 14 Mar 19, 00:59

And can I also apply spell check to the text while executing the macro or copying into the clipboard ?

Peter Stotz
PhraseExpress Expert
Posts: 761
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 14 Mar 19, 10:57

No.
For this you would have to copy the text into an application that has a spell checker.
Peter
Windows 10 - PhraseExpress v14.0.131

cybmatrix
Posts: 9
Joined: 12 Mar 19, 18:42

Post by cybmatrix » 15 Mar 19, 02:58

OK thanks Peter.
I'll need to set some rules into the replace functions, the way I can remove from text some orthographic errors, double points, letters accented badly, emoticon... etc.
Is there a tutorial available for this ?

Peter Stotz
PhraseExpress Expert
Posts: 761
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 15 Mar 19, 12:58

@cybmatrix
Manuals see here https://www.phraseexpress.com/manuals.htm

Especially interesting for text operations with PhraseExpress v14 is the use of regular expressions.
A "regular expression" is a search pattern for strings.
To use regular expressions in PhraseExpress, however, some knowledge is required:
- There is a lot of information about RegEx on the net,
- The developers refer to the RegEx-documentation
https://perldoc.perl.org/perlre.html
and to the additional examples here: http://jkorpela.fi/perl/regexp.html#ex
- And here in the forum there's also help ...

Peter
Windows 10 Home - PhraseExpress v14.0.131

cybmatrix
Posts: 9
Joined: 12 Mar 19, 18:42

Post by cybmatrix » 15 Mar 19, 18:41

OK Peter, i need to convert the text in simple text without formatting at first.
Then filter with a regex all non text\numbers chars and finally remove also : emoticons, double spaces, !!!, ???, ......., ------------.

Please, can you create a macro for me, like the first one !?
Thank you so much.

Peter Stotz
PhraseExpress Expert
Posts: 761
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 15 Mar 19, 23:07

@cybmatrix
Here an example for you.
Note: All Text between (* ... *) are comments - (* this is a comment *)
The following macro program ...
1. removes all blank lines and lines with whitspaces only
- Regex Search: ^\h*\R
- Regex replace: (nothing)
2. will replace all tabs and all consecutive spaces with 1 space character
- Regex search: \h+
- Regex replace: <space>

Makrocode (with comments)

Code: Select all

{#setclipboard}{#clipboard -copy}(* 
1.  remove blank lines and lines with whitspaces only 
*){#setclipboard {#regexrep -text {#insertclipboard} -expr ^\h*\R -repexpr }}(* 
2.  replace all tabs and all consecutive spaces with one space character
*){#setclipboard {#regexrep -text {#insertclipboard} -expr \h+ -repexpr  }}
Source code text (example, → symbolic for tabs, ˽ symbolic for spaces ):
»This →→→→is a text →

with several ˽ ˽ ˽ ˽ ˽ empty lines ˽ ˽ ˽ ˽ and some

multiple tabs and spaces.


«


Result - can be inserted into a target application with CTRL+v
»This is a text
with several empty lines and some
multiple tabs and spaces.
«


So - now it's your turn...
Peter
Windows 10 - PhraseExpress v14.0.131

cybmatrix
Posts: 9
Joined: 12 Mar 19, 18:42

Post by cybmatrix » 16 Mar 19, 12:27

Ohhh thanks Peter !
Will try next days. :-)

cybmatrix
Posts: 9
Joined: 12 Mar 19, 18:42

Post by cybmatrix » 20 Mar 19, 15:40

Hello Peter.
All is working with regex and nested macros, exept the AUTOCASE function.
I'd like to, first of all, convert clipboard content to "sentence mode" with only the first letter uppercase.
And as final step, remove all leading and trailing spaces ... but this will not work properly, i tried with a processing step added to one othe the nested macro ... but nothing happened.

I also need to convert something like ( h3ll0 ) to ( hello ).
Some words are "encoded" with numbers, but i cannot remove or convert all numbers ... i need to check if are there non-numbers chars before\after and then convert ... please help me, this is really too complex for me to set.

Peter Stotz
PhraseExpress Expert
Posts: 761
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 21 Mar 19, 10:38

@cybmatrix
"AUTOCASE function.."
Please give us a typical example:
Text before
versus
Text after

"remove all leading and trailing spaces"
Use the #trim-macro (see the example below)

"specific conversions ( h3ll0 ) to ( hello )" and so on
You probably can't consider every particular variant...
Handle 'automatically' the most common cases with RegEx and/or #replace.
And finally check the result 'manually'.
Here an example with (* comments *):

{#clipboard -copy}(*
1. remove all leading and trailing spaces
*){#setclipboard {#trim {#insertclipboard}}}(*
2. remove blank lines and lines with whitspaces only
*){#setclipboard {#regexrep -text {#insertclipboard} -expr ^\h*\R -repexpr }}(*
3. Remove_multiple_consecutive_whitespaces
*){#setclipboard {#regexrep -text {#insertclipboard} -expr \h+ -repexpr }}(*
4. ... more applications of Regex and #replace
...
...
×. Final manual text check:
*){#setclipboard {#input -head Final text check: -def {#insertclipboard}}}(*
Result output (corresponds to CTRL+v)
*){#insertclipboard}

Peter
Windows 10 - PhraseExpress v14.0.131

cybmatrix
Posts: 9
Joined: 12 Mar 19, 18:42

Post by cybmatrix » 23 Apr 19, 17:26

Thanks Peter.

Post Reply