Use regular expressions match Double-byte characters failed

User-to-User discussion about the PhraseExpress macro programming.
Post Reply
kewin
Posts: 23
Joined: 17 Dec 20, 02:45

Use regular expressions match Double-byte characters failed

Post by kewin » 13 Jan 21, 10:13

Hello everyone,

I want to use a regular expression to match some double-byte character in A paragraph, but there is no output result.

Three double-byte characters should be matched, then three characters are replaced with A, B, and C.
before:
_________________________________________________________
DocumentModel document = new DocumentModel();

Section section = new Section(document);
document.Sections.Add(section);

Paragraph paragraph = new Paragraph("文件");
section.Blocks.Add(paragraph);

Run run = new Run(document, "文字");
paragraph.Inlines.Add(run);

document.Save("文件名");
_________________________________________________________

result of the output I expect is below, Is it possible? Any suggestions are welcome. Thanks in advance!
_________________________________________________________
DocumentModel document = new DocumentModel();

Section section = new Section(document);
document.Sections.Add(section);

Paragraph paragraph = new Paragraph("A");
section.Blocks.Add(paragraph);

Run run = new Run(document, "B");
paragraph.Inlines.Add(run);

document.Save("C");
_________________________________________________________

Code: Select all

{#setclipboard {#settemp -name zw -content DocumentModel document = new DocumentModel();

Section section = new Section(document);
document.Sections.Add(section);

Paragraph paragraph = new Paragraph("文件");
section.Blocks.Add(paragraph);

Run run = new Run(document, "文字");
paragraph.Inlines.Add(run);

document.Save("文件名"); -embeddata JVslUEVYX0VNQkVEX1BBUkFNUyVdJXsjcmVnZXhnZXQgLXRleHQgJVsldmFsdWUlXSUgLWV4cHIgW1x1NGUwMC1cdTlmYTVdKyAtZmluZGFsbCAtZGVsaW0gLX0= -variablename Set variable} -variablename Put text into clipboard}{#insertclipboard -variablename Insert text from clipboard}

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

Post by Technical Support » 13 Jan 21, 10:58

First, you need to use the following syntax for matching multibyte characters: \x{hex code}
Second, your variable must output its content for your phrase to work:

Code: Select all

{#setclipboard {#settemp -name zw -content DocumentModel document = new DocumentModel();

Section section = new Section(document);
document.Sections.Add(section);

Paragraph paragraph = new Paragraph("文件");
section.Blocks.Add(paragraph);

Run run = new Run(document, "文字");
paragraph.Inlines.Add(run);

document.Save("文件名"); -output -embeddata JVslUEVYX0VNQkVEX1BBUkFNUyVdJXsjcmVnZXhnZXQgLXRleHQgJVsldmFsdWUlXSUgLWV4cHIgW1x4ezRlMDBcXFx9LVx4ezlmYTVcXFx9XSsgLWZpbmRhbGwgLWRlbGltIC19 -variablename Set variable} -variablename Put text into clipboard}{#insertclipboard -variablename Insert text from clipboard}

kewin
Posts: 23
Joined: 17 Dec 20, 02:45

Post by kewin » 13 Jan 21, 23:39

Thank you for your help

In the above example, three values are matched, which are
文件
文字
文件名

How to get the index of each value? I need to replace the value with another value . Please see the picture below
Image

Is that possible? Thanks in advance
Expected results:
___________________________________
DocumentModel document = new DocumentModel();

Section section = new Section(document);
document.Sections.Add(section);

Paragraph paragraph = new Paragraph("A");
section.Blocks.Add(paragraph);

Run run = new Run(document, "B");
paragraph.Inlines.Add(run);

document.Save("C");

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

Post by Technical Support » 13 Jan 21, 23:52

Well, you could search for one value instead of all and if smth is found, then replace it, set some variable to the next replacement text and search again until nothing is found.

kewin
Posts: 23
Joined: 17 Dec 20, 02:45

Post by kewin » 13 Jan 21, 23:55

In the example above, I couldn't predict three double byte values, so I wanted to use the index to determine them

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

Post by Technical Support » 14 Jan 21, 00:16

No need to predict. Just call the same phrase to replace one value until nothing is found. There are no array like structures in PhraseExpress.

kewin
Posts: 23
Joined: 17 Dec 20, 02:45

Post by kewin » 14 Jan 21, 00:23

Can you provide the code? I'm very sorry, I don't know the operation steps, thanks a lot

kewin
Posts: 23
Joined: 17 Dec 20, 02:45

Post by kewin » 14 Jan 21, 02:05

If a double byte character is matched, an input box will pop up to prompt for the character(Manual input A or B or C) to be replaced

Until all double byte character replacement operations are completed

I hope someone can help me to implement the code of this function

Post Reply