Hi everybody,
I am currently struggling with javascript and regular expressions.
My purpose is to count "M" letters not preceded by F in a target string (see below).
The regex pattern "[^F]M" I thought to use doesn't work (even though I have successfully tried it in a freeware that checks regular expressions against test strings); I had to change it to "\.M|M\."
I have also encountered problems using "^" and "$" as start and end locators (not in this specific example).
Am I doing something wrong with the javascript or does the adobe regular expression engine have specific limitations I am not aware of?
Thank you for your help and please forget my terrible English.
Pierpaolo
-------------- target string
FC.FY
FM.CF.m
M.FV.FT
Fr.FV.FY
m.C.F
FC'.M
CF.FM
m.CF
FM.C
--------------javascript code NOT working
var tot=0;
var s = this.getField("Blends").value;
var match = /[^F]M/.test(s);
if (match) {
tot = (s.match("[^F]M","g")).length;
}
event.value = tot;
-----------------------------------
Here you can find out more about it:
http://www.w3schools.com/js/js_obj_regexp.asp
http://www.w3schools.com/jsref/jsref_obj_regexp.asp
As to your question. I would do it in the following way:
patt1 = /FM/g;
patt2 = /M/g;
tot = s.match(patt2).length - s.match(patt1).length;
There might be a way to combine both expressions into one, but that should work as well.
- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com