Pages: 1
Print
Author Topic: Search/Replace with Regular Expression using Derek's code  (Read 2186 times)
russurquhart1
Member

Posts: 46


« on: January 28, 2014, 01:46:52 PM »

Hi Derek,

One of our guys, finding some code you had posted on this forum, wrote a macro of the following:

<MACRO name="CompleteWikiTransfer" key="" lang="JScript"><![CDATA[
var rng = ActiveDocument.Range;
rng.SelectAll();
var wholeDoc = rng.TextWithRM;
Application.Alert(wholeDoc)
var rx = /\|-[^s]*style=[^\<]*/g;
var newDoc = wholeDoc.replace(rx,"");
Application.Alert(newDoc);
rng.Delete();
rng.PasteString(newDoc);
]]></MACRO>

But the macro for him, and me, doesn't seem to do anything.

Any ideas?

thanks,


Russ
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #1 on: January 28, 2014, 02:15:54 PM »

Looks like it is based on something I suggested during a discussion with someone else as a possible workaround for finding and replacing entities. We both decided it wasn't a good idea to use in that instance and came up with a better solution for that problem. http://forums.xmetal.com/index.php/topic,3275.0.html

Not sure what that regular expression is supposed to be doing. It isn't mine.
The rest of that code works for me, provided I put in a regex I understand and run it against a document that has some content the regex will match.

I'd concentrate on the regular expression as being the problem part of your code. Presumably it is just not matching what you want it to match.
Logged
russurquhart1
Member

Posts: 46


« Reply #2 on: January 28, 2014, 03:56:04 PM »

The REg Ex is looking for style commands inserted before an element begin.

I'll have to look at this because when i tested it, i tried just using the string 'the' (without quotes) and the same, i.e. no results.

thanks,

Russ
Logged
Pages: 1
Print
Jump to:  

email us