udfRegExpReplace() in binary buffer

Started by cssyphus, September 10, 2017, 05:05:02 PM

Previous topic - Next topic

cssyphus

I am programmatically modifying a large text file containing some HTML/JS code and need to "mark" locations where there is a space between two selectors, such as between an ID and className, as in $('#btnOne .subElement'). To find these, I need a RegEx. The following RegEx works well in Notepad++, and here in this jsFiddle (https://jsfiddle.net/m7pamjLp/1/), to identify substrings in which to replace the spaces.

>>>  \$\(['"].+ .*\)\.  <<<

The text (code) to be searched is approx 7500 lines, 250K, so wish to do this in a binary buffer. Also, the presence of the percent sign in the txtAdvisory string (above) breaks udfRegExpReplace(). I am hoping that using a binbuf will also fix that problem.

How would I write winbatch code to do a RegEx replace in a binary buffer?

I found Detlev's wonderful RegEx UDFs, but cannot think how to adapt udfRegExpReplace() to use binbufs. A little help?

td

There is no reason to use a binary buffer based on the information you have provided.  A file of 750K bytes is not that large and easily handled by the FileGet function.  Using a binary buffer would not save any computer memory and may even cause your script to use more (not that it would be an issue with a file in this size range.) 

The percent sign only causes issues when it is placed in a string literal and the way to avoid that is to escape it in that string literal, i.e., use '%%' instead of '%'.

FWIW, I prefer using the FCL's  "System.Text.RegularExpressions.Regex" class for regular expression processing in scripts because it has a more complete implementation than the COM Automation version.   However, the regex you want to use is not that complex so you likely don't need a full implementation.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

cssyphus

Thanks Tony.

(1) Is there an example somewhere of using the .NET System.Text.RegularExpressions.Regex in a WinBatch script?

(2) I'm not a .NET coder and not familiar with the FCL, so coming at this new. Yet I can see how useful it would be to have access to all the FCL's functions/classes. Is there a primer for using the FCL in general with WinBatch scripts? (Preferring examples to explanation)

td

There is a whole section of examples of WinBatch CLR hosting in the Tech Database.  It includes several using the "System.Text.RegularExpressions.Regex" class.  Of course, the three WILL functions ObjectClrNew,  ObjectClrOption, and ObjectClrType used to initiate and support CLR hosting are documented in the Consolidated WIL Help file.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade