Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

What's the best option to work with regular expressions


What's the best option to work with regular expressions

Hi experts!

Currently I'm working in a kind of text analyzer, and I am thinking on
the use of regular expressions, however I don't know yet what's the
best option, I have seen that ACL has an option in order to work with
regex, but also I'm thinking in the possibility of the use of
javascript, If I decide to use javascript I would like to know how can I
call my javascript file, I have been trying to make some experiments
with js_source command from Arbortext, but until now I don't know if
there's another response from js_source different to a number indicating
me if the call was successful, so please any of you guys could provide
me of more details about js_source command and also about the match ACL

As always I really appreciate your time and support,

Paulette Amparo

Hi Paulette--

Arbortext has quite good Javascript support, and you'll find that Javascript regex handling is much more complete than what ACL supports.

The easiest way to do what you are describing is to:

1) define a Javascript function to do the text operation you want. You will pass the input information as parameters, and return the result as a string. For example, something like this:

function noSpaces(text) {
return text.replace(/ /g, '');

2) make sure the javascript file that contains the function definition gets loaded on startup, either by putting it in $APTCUSTOM/init (with a .js extension), or by explicitly loading it using the js_source() function in one of your ACL startup files.

3) when you want to apply the function, use the javascript() ACL function. It takes a string of Javascript code and executes it, returning any value to ACL that the Javascript code returns. You'll need to compose the Javascript function call with the parameter values inserted as strings. Using the pervious example, if you wanted to get the title of a document without the spaces, you could do something like this in ACL:

# assume $title var contains the title text
local fname = javascript("noSpaces(" . $title . ")");

Once you get your brain around that model, it's pretty easy to get info back and forth between Javascript and ACL.


Sent from my iPad

Thanks for your help, this has been pretty useful; I decided to put my *.js file inside custom/init folder and then just load it with js_source and called my function with javascript command. It's working now.

Thank you so much, I really appreciate your time and support.


Top Tags