We want to have FirstName LastName (Abbr.) displayed as FirstName LastName.
I'm trying with regex but is not working, I'm new in velocity, and I would like kindly ask what's wrong in the script:
I tried this version:
#set ($string = ${lead.Account_Owner__c})
#set ($var1 = $string.replace("/\(\w+\)/", ""))
This is the Account Owner Without Abbreviation: $var1
This is not removing anything.
-----
This the other version I tried:
#set ($string = ${lead.Account_Owner__c})
#set ($var1 = $string.replace(/\(\w+\)/, ""))
This is the Account Owner Without Abbreviation: $var1
This script gives an error.
Thanks in advance!
Cheers,
Cristina
#velocity my token#velocity script #velocity error #velocity scripting
Please highlight your code using the Syntax Highlighter (use Java as it's closest to VTL) then we'll continue.
Hello Sanford! Thanks a lot for your reply!
Do you think we can continue now?
#set ($string = ${lead.Account_Owner__c})#set ($var1 = $string.replace("/\(\w+\)/", ""))This is the Account Owner Without Abbreviation: $var1#set ($string = ${lead.Account_Owner__c})#set ($var1 = $string.replace(/\(\w+\)/, ""))This is the Account Owner Without Abbreviation: $var1
You're overly restricting the characters in parens. You want to strip anything in parentheses that's anchored at the end of the string, including leading and trailing whitespace.
#set ($accountOwner = $lead.Account_Owner__c)
#set ($accountOwnerSimple = $accountOwner.replaceAll("\s*\(.*\)\s*$", ""))
This is the Account Owner Without Abbreviation: $accountOwnerSimple
Also:
Thank you so much for guides! I need to do more training on velocity script, and I'm happy to learn from the bests!