Quantcast
Channel: Adobe Community: Message List - FrameMaker Scripting
Viewing all articles
Browse latest Browse all 3715

Re: Finding text with RegEx

$
0
0

Hello Klaus,

 

By coincidence I am working on a similar problem today, using regular expressions in ExtendScript. My problem cannot be solved directly, as the regular expression engine in ExtendScript has a serious flaw. The usage of the "\1", "\2" etc strings to use the matched substrings does NOT work, so having a replacement string use some of the stuff that was matched has to be done differently. Bummer. The problem has been reported earlier but is located in the ExtendScript Toolkit, not in FrameMaker, and I am not sure how quick the ESTK development team at Adobe will pick this up.

 

I have created a workaround, which may also help you.

 

Instead of using the search method with a regular expression, you can use the match method. This either returns null (in which case there was no match) or an array of matched strings (even if it is only 1 string long). The elements in that array can then easily be replaced by the placeholder you are intending to put in. The trick in finding all matches to a single regular expression is to add the indicator "g" for global search. Try the followind and see if that is what you wanted to have.

 

function GetTempCitation (pgfText) {

    var regex = /(\[\[[^\]]+\]\])/g;

          return pgfText.match ( regex );

}

 

Note that the alert( ) function shows the full array contents, separated by a comma. If there were no matches, the returned value is null. So if you want to access the separate strings, you will have to loop through the resulting string array, after first testing for a null value.

 

Good luck

 

Jang


Viewing all articles
Browse latest Browse all 3715

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>