View Single Post
  #2  
Old April 6th, 2016, 04:24 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Changing Fonts for Characters

Right now, you're capturing all numbers and assigning them to the '$1' variable which you then wrap in your font tag. If you want to expand that regexp to include parentheses and hyphens, I think this would work for you:

Code:
return Field("Address").replace(/([\(\)\-\d]+)/g, '<span font="Gotham Medium">$1</span>');
Here's a more in depth break-down of how it works:
Code:
var find = new RegExp(
  '(' +   // Parenthesis CAPTURE matched patterns and assign them to $1
  '[' +   // Square brackets denote a character set that the RegExp should match
  '\\(' + // First character to match: ( <-- Open parenthesis
          // Note that we escape so we don't start another capture group
  '\\)' + // Second character to match: ) <-- Close parenthesis
  '\\-' + // Third character to match: - <-- hyphen
  '\\d' + // All digits 0-9
  ']' +   // Close the square brackets because we only want to match what's inside
  '+' +   // Plus sign means we want to match 1 or more of the characters in the []
  ')'     // Close parenthesis to end capturing
 ,'g');   // g means "Match globally"

// Each captured match is assigned to $1 so we can wrap it in font tags 
var replace = '<span font="Gotham Medium">$1</span>';

return Field("Address").replace(find,replace);
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote