Jump to content

How to do StringRegExpReplace in my example?


Go to solution Solved by Nine,

Recommended Posts

If I have a textfile:

Comparing files D:\DOCUMENTS\LEARN\EXAMPLE1 and D:\DOCUMENTS\LEARN\EXAMPLE2
00000010: 5B 5D
00000014: 28 B8
00000E40: B8 C0
00001159: C0 80
0000115A: 39 28
00001168: 90 20
00001169: 84 5E
0000116A: 39 28
00002878: 1C 0C
0000287B: 80 00
FC: D:\DOCUMENTS\LEARN\EXAMPLE1 longer than D:\DOCUMENTS\LEARN\EXAMPLE2

Then, I want to do StringRegExpReplace so that it become:

00000010: 5B 5D
00000014: 28 B8
00000E40: B8 C0
00001159: C0 80
0000115A: 39 28
00001168: 90 20
00001169: 84 5E
0000116A: 39 28
00002878: 1C 0C
0000287B: 80 00

How to do it?

I tried in https://regex101.com/ but I still confused

Link to comment
Share on other sites

  • Solution

If all the lines you want to keep start with a 0 :

$sText = StringRegExpReplace(FileRead("1.txt"), "(?m)^[^0].*\v*", "")

But you may want to use this instead :

Local $aList = StringRegExp($sResult, "(?m)^([0-9A-F]{8}): ([0-9A-F]{2}) ([0-9A-F]{2})$", 3)

where $sResult is the output of fc.exe 

Edited by Nine
Link to comment
Share on other sites

@Nine
Sorry for unimportant question

When I do your first answer to this file below

the resulting file will have two empty line in the end (two last line will be empty)

Did I do something wrong?

Is there any way I can also remove that two empty line in a single "StringRegExpReplace"

 

========================================================================================================

 

Sorry, I am trying and learning both of your answer

Thank You

FC Example.txt

Edited by HezzelQuartz
Link to comment
Share on other sites

13 hours ago, HezzelQuartz said:

the resulting file will have two empty line in the end (two last line will be empty)

(Aside : my console output is identical to @Nine 's.)

However, as soon as you write the output to a file, there is one (not two as in your case) blank line. This is comprehensible, as the last line does fulfill the RegEx pattern and is therefore replaced by “”.

Replace.jpg.4f57f91fb379c3139a919db6d4272133.jpg

I would prefer the array variant (as already suggested by Nine) - this provides more flexible access to the individual elements.

Edited by Musashi
insert picture

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

As @Musashi said, there is not blank line at the end beside the fact that the last line :

0000287B: 80 00

Is also finished by @CRLF like all the others before.  If you don't want it just use StringStripWS and remove those trailing characters.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...