dreimer Posted June 18, 2014 Share Posted June 18, 2014 How can I write a rule to superscript multiple characters in one variable field? Currently I have this to superscript a Trademark symbol. var s = Field("Description New 1"); return s.replace(/™/g,"<superscript>™</superscript>"); How can I have a single rule to also include Register and Asterisks as well. I tried to simple do this: var s = Field("Description New 1"); return s.replace(/™/g,"<superscript>™</superscript>"); return s.replace(/®/g,"<superscript>®</superscript>"); return s.replace(/*/g,"<superscript>*</superscript>"); But that obviously doesn't work. It only looks at the first Trademark return statement. Sorry if this is really easy, but still learning JavaScript. TIA Quote Link to comment Share on other sites More sharing options...
step Posted June 18, 2014 Share Posted June 18, 2014 (edited) Don, try this. I edited the regexp to search for three HTML entities (instead of one single entity) and superscript the matches: var s = Field("Description New 1"); return s.replace(/(™|®|*)/g,'<superscript>$1</superscript>'); Alternatively, you could keep the same code that you have if you make some slight changes: var s = Field("Description New 1"); s = s.replace(/™/g,"<superscript>™</superscript>"); s = s.replace(/®/g,"<superscript>®</superscript>"); s = s.replace(/*/g,"<superscript>*</superscript>"); return s; Or do multiple replaces on a single return line: var s = Field("Description New 1"); return s.replace(/™/g,"<superscript>™</superscript>").replace(/®/g,"<superscript>®</superscript>").replace(/*/g,"<superscript>*</superscript>"; Edited June 18, 2014 by step text editor was converting asterisk entity character to * Quote Link to comment Share on other sites More sharing options...
dreimer Posted June 18, 2014 Author Share Posted June 18, 2014 Perfect, thanks step. I will use the second one since I can understand how that is written and can make changes if necessary. Quote Link to comment Share on other sites More sharing options...
step Posted June 18, 2014 Share Posted June 18, 2014 To elaborate on the first regexp: return s.replace(/[color="Red"]([/color][color="Cyan"][color="Cyan"]™[/color][/color][color="Lime"]|[/color][color="Cyan"]®[/color][color="lime"]|[/color][color="Cyan"]*[/color][color="red"])[/color]/g,'<superscript>[color="red"]$1[/color]</superscript>'); The parentheses (in red) capture the match and store it in '$1' which I'm returning within the superscript tags The pipes (in green) indicate "or." So find the registration mark entity OR the trademark entity OR the asterisk entity. To add another entity, you would put another pipe after the asterisk entity followed by the new entity you're searching for. The items in blue are (obviously) the entities you're searching for. Just wanted to explain how that works for future reference. Quote Link to comment Share on other sites More sharing options...
dreimer Posted June 18, 2014 Author Share Posted June 18, 2014 OK thanks for the explanation. Thanks again!! Quote Link to comment Share on other sites More sharing options...
dreimer Posted June 20, 2014 Author Share Posted June 20, 2014 How could I adjust the 2nd example you provided to change point sizes independently? The client is OK with the size of the Trademark and Register using the default global settings but would like the asterisk to be smaller. TIA Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.