Skip to main content
1-Visitor
December 18, 2012
Question

What's the best option to work with regular expressions

  • December 18, 2012
  • 2 replies
  • 900 views
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
command?

As always I really appreciate your time and support,
Regards,

Paulette Amparo

    2 replies

    18-Opal
    December 18, 2012
    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.

    --Clay

    Sent from my iPad

    pzorrilla1-VisitorAuthor
    1-Visitor
    December 19, 2012

    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.


    Paulette