back to forum.

Topic: How to build java script transformation around regular expression

Topic by
chrisf

2011-12-27
09:51

How to build java script transformation around regular expression

I have a regular expression which I want to use as a java script transformation in Data Cleaner. Is there documentation or an example available on how to do that?

Reply by
kasper

2011-12-27
12:02
That would be documentation on javascript then, since DataCleaner's javascript transformer simply adheres to the rules of JavaScript.

I like w3schools reference, which also has a pretty good reference on regexes:
http://www.w3schools.com/jsref/jsref_obj_regexp.asp

You define a regex like this:
var patt=/hello/g;

And you match/test it using either of these functions then:
var matched = patt.test("hello world");
var matchedPart = patt.exec("hello world");

A simple example could be something like this:
function eval() {
var patt=/hello/g;
return result + ": " + patt.test(values[0]);
}
eval();

PS: You could also take a look at the Regex Parser extension, maybe it's what you need?

Reply by
chrisf

2011-12-27
13:33
Actually the regex parser did the job for now. Next thing is that I will need a filter, so I will use your tips to try and create a JS filter with my regex.

Thanks!

You need to be logged in to participate

In order to post your own comments on this topic, you need to be logged in.

Username:

Log in by clicking the login link at the top of the screen

 

Go back to forum.