We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How to get the length of string containing HTML Entities using Perl?

Medium Priority
413 Views
Last Modified: 2013-12-25
I have a string variable containing mix of HTML Entities of Japanese characters, I would like to get the length of the string, and treat each HTML Entity as length of 2, and standard English character as length of 1.

I would like to use regular express for matching the &#xxxxx; counts, how can I get this done?

eg. $str contains abc&#xxxxx;123&#xxxxx;xyz

Normally, I would get the length of 25, but instead, I would like to get length of 11.
Comment
Watch Question

Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
print $length=()="abc&#xxxxx;123&#xxxxx;xyz"=~/&.*?;|./g    
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
Do you want a length of 11 or 13?
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.