Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 11th, 2014, 07:44 AM
-Lisa- -Lisa- is offline
Senior Contributor
 
Join Date: Sep 2008
Location: Long Island, NY
Posts: 190
Default Using two Replace Functions in one field

I've got the first half of this rule working, but I can't seem to figure out the second and was hoping for some guidance.

I need to replace the registered trademark in a product name and then follow that up with italicizing the second half of the product name. So far I have:

Code:
return Field("ProductDescription").replace(/DENTtips Master/g, "DENTtips" + '<f name="Compatil Fact It"> Master</f>);
The registered mark needs to come right after "DENTtips" and before "Master". However, because the word "master" may be used in another grammatical context, I cannot force a global replace around "master" By itself. I tried the following which didn't work:

Code:
return Field ("ProductDescription").replace(/DENTtips&reg; Motion | DENTtips® Motion/g, "DENTtips + '<superscript>&reg;</superscript>' + '<f name=Compatil Fact It"> Master</f>);
I know I'm missing something easy here!!
__________________
Lisa B.
FusionPro VDP Creator 10.0.16
Adobe Acrobat Pro DC 2018
Mac OS X 10.13.6 (High Sierra)
Reply With Quote
  #2  
Old November 11th, 2014, 08:07 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 957
Default Re: Using two Replace Functions in one field

Lisa, if you're trying to capture separate patterns, put them inside parentheses like so:
Code:
return Field ("ProductDescription").replace(/(DENTtips&reg; Master)|(DENTtips® Master)/g,'DENTtips<superscript>&reg;</superscript><f name="Compatil Fact It"> Master</f>');
Also, I'm not sure if it's on purpose or not, but your code is searching for "Motion" and in your post you say you're trying to replace "Master" so I made that edit.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #3  
Old November 11th, 2014, 08:19 AM
-Lisa- -Lisa- is offline
Senior Contributor
 
Join Date: Sep 2008
Location: Long Island, NY
Posts: 190
Default Re: Using two Replace Functions in one field

Thanks Step. I appreciate the reply.

Unfortunately, that doesn't seem to return the result I need. In fact, neither format style is being applied. I don't see the registration mark super-scripted nor is the word "Master" italicized the way it should be.

(BTW - thanks for changing that in my code. I've got two different products I need to replace, one is Master the other, Motion. Looks like I copied the wrong one into the thread!)
__________________
Lisa B.
FusionPro VDP Creator 10.0.16
Adobe Acrobat Pro DC 2018
Mac OS X 10.13.6 (High Sierra)
Reply With Quote
  #4  
Old November 11th, 2014, 10:08 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,694
Default Re: Using two Replace Functions in one field

Try this:
Code:
return Field("ProductDescription").replace(/(DENTtips) (Master)/g, '$1<superscript>&reg;</superscript>&#32;<f name="Compatil Fact It">$2</f>');
To break this down: the $1 and $2 in the second parameter call out the first and second "captured" substrings, denoted by parentheses in the Regular Expression in the first parameter. So those always return "DENTtips" and "Master". The rest is just markup: the &#32; is there to ensure that the space is typeset (otherwise a space between two tags would be collapsed by FusionPro's tagged markup parser). Also note the quotes in the <f> tag, which are needed as the "name" attribute value has spaces.
Quote:
Originally Posted by -Lisa- View Post
I've got two different products I need to replace, one is Master the other, Motion.
You can do that with a tweak to the Regular Expression:
Code:
return  Field("ProductDescription").replace(/(DENTtips) (Master|Motion)/g, '$1<superscript>&reg;</superscript>&#32;<f name="Compatil Fact It">$2</f>');
More info:
https://developer.mozilla.org/en-US/...ar_Expressions
https://developer.mozilla.org/en-US/...String/replace
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #5  
Old November 11th, 2014, 11:11 AM
-Lisa- -Lisa- is offline
Senior Contributor
 
Join Date: Sep 2008
Location: Long Island, NY
Posts: 190
Default Re: Using two Replace Functions in one field

Quote:
Originally Posted by Dan Korn View Post
Try this:
Code:
return Field("ProductDescription").replace(/(DENTtips) (Master)/g, '$1<superscript>&reg;</superscript>&#32;<f name="Compatil Fact It">$2</f>');
To break this down: the $1 and $2 in the second parameter call out the first and second "captured" substrings, denoted by parentheses in the Regular Expression in the first parameter. So those always return "DENTtips" and "Master". The rest is just markup: the &#32; is there to ensure that the space is typeset (otherwise a space between two tags would be collapsed by FusionPro's tagged markup parser). Also note the quotes in the <f> tag, which are needed as the "name" attribute value has spaces.
Thanks, Dan! This was super helpful. And I really appreciate the additional explanation and the links!

My only concern is that there are only limited instances where the registered trademark is required. This template will be used in conjunction with a MarcomCentral storefront. The users know when the registered trademark is and is not required. Therefore I need to account for both scenarios.

For instance, using "Motion" as the example here, if someone enters "DENTtips® Motion", the end result should superscript the registered mark and italicize the word "Motion". However if the mark is not entered, and only "DENTtips Motion" is returned, I still need "Motion" to be italicized.

I tried altering your code to:
Code:
return Field("ProductDescription").replace(/(DENTtips) (&reg;) (Master)/g, '$1$2<superscript>&reg;</superscript> <f name="Compatil Fact It">$3</f>')
But that doesn't seem to give me the desired result...
__________________
Lisa B.
FusionPro VDP Creator 10.0.16
Adobe Acrobat Pro DC 2018
Mac OS X 10.13.6 (High Sierra)
Reply With Quote
  #6  
Old November 11th, 2014, 12:09 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,694
Default Re: Using two Replace Functions in one field

Quote:
Originally Posted by -Lisa- View Post
Thanks, Dan! This was super helpful. And I really appreciate the additional explanation and the links!

My only concern is that there are only limited instances where the registered trademark is required. This template will be used in conjunction with a MarcomCentral storefront. The users know when the registered trademark is and is not required. Therefore I need to account for both scenarios.

For instance, using "Motion" as the example here, if someone enters "DENTtips® Motion", the end result should superscript the registered mark and italicize the word "Motion". However if the mark is not entered, and only "DENTtips Motion" is returned, I still need "Motion" to be italicized.

I tried altering your code to:
Code:
return Field("ProductDescription").replace(/(DENTtips) (&reg;) (Master)/g, '$1$2<superscript>&reg;</superscript> <f name="Compatil Fact It">$3</f>')
But that doesn't seem to give me the desired result...
This gets a bit more complicated to do with a String.replace call and a Regular Expression, but I think this will work:
Code:
return TaggedDataField("ProductDescription").replace(/(DENTtips)(&reg;|) (Master|Motion)/g,
    function(all, m1, m2, m3){return m1 + '<superscript>' + (m2 || '&reg;') + '</superscript>&#32;<f name="Compatil Fact It">' + m3 + '</f>';});
Here, instead of a string with replacement patterns such as $1, $2, etc., we're specifying a function which takes those matched substrings as parameters. We make the second match optional by saying basically "or nothing" in the RegExp, and then we handle that in the function by saying "or '&reg;'". Note also that, since we added another set of capturing parentheses, the "Master|Motion" part is now the third match. I've also changed the Field call to TaggedDataField so that, if the user does enter a literal ® symbol, it gets converted to the entity (and so that other things which need escaping in tagged markup get handled properly).
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:49 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.