Jump to content

Superscript Multiple Characters


Recommended Posts

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

Link to comment
Share on other sites

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 by step
text editor was converting asterisk entity character to *
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...