Ask a Question related to Adobe Acrobat Macintosh, Design and Development.
-
Garrett_Cobarr@adobeforums.com #1
JavaScript? Putting a variable in the midst of a Regular Expression.
I was reading a great article by Kas Thomas, "Save Yourself Some Typing with 'With'" at PlanetPDF. I really don't care much for the term guru, I think it is way overused, but if anyone deserved it, it would be him. Really great informative JavaScript info and he is funny too.
He had this script chunk below and it was very close to something I am doing. Although, how I was going about it was much less elegant so I wanted to adapt his example to what I was trying to accomplish.
var subtotal = 0.0;
var fld;
with (this) { // default object is 'this'
for (var k = numFields; k; k--)
{
fld = getField(getNthFieldName(k-1));
if (fld.name.match(/amt/i))
subtotal += fld.value;
}
}
Although the article is about using the 'with' statement to conserve and compact your code what caught my eye was this very elegant loop for iterating through a number of fields, a very common need.
But what has stopped me is that his example... (fld.name.match(/amt/i)) is a fixed match for a known word, in this case, any occurence of 'amt'. I need to have a variable in the middle of the same RegEx because my search is arbitrary, I do not know what the word value will be, but I have not seen an example of this anywhere.
Does anyone know how this bit of syntax gymnastics might be accomplished?
Garrett_Cobarr@adobeforums.com Guest
-
Regular Expression
Hi, I am writing a script that parses an html file (which has been retrieved as a scalar by LWP::UserAgent). The script looks for everything in... -
Regular expression help
Hi, I'm pretty new to regular expressions. Before, I used to write long-winded and buggy segments of code with PHPs string functions to extract... -
Regular Expression - Need Help
Hi, I have the following: <cfset input =" Origin: cohnok-530a (190.068.59.250) Type: ... -
javascript regular expression error
It works here but it's not fool proof. You didn't say why it isn't working for you. It could be that your putting in odd characters in the field or... -
[PHP] Regular Expression
Thanks Wendell. This is exactly what I was looking for. -----Original Message----- From: Wendell Brown Sent: Tuesday, July 08, 2003 4:47 AM... -
Graham_O_Connor@adobeforums.com #2
Re: JavaScript? Putting a variable in the midst of a Regular Expression.
Try this for the if statement:
if (util.printx("<*",fld.name).match(reqstrvar))
where reqstrvar is the variable containing the required string.
Graham_O_Connor@adobeforums.com Guest
-
Garrett_Cobarr@adobeforums.com #3
Re: JavaScript? Putting a variable in the midst of a Regular Expression.
Graham, thanks! I just stumbled on your answer, the forum is acting up and not sending out subscriptions.
Here is a link to George's response on Planet PDF...
<http://forum.planetpdf.com/webboard/wbpx.dll/~planetpdfforum>
Garrett_Cobarr@adobeforums.com Guest



Reply With Quote

