Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Matching a truncated string to add missing characters

Not always truncated at the same place

9:38 pm on Jan 23, 2011 (gmt 0)

5+ Year Member

Say I have a string like "This page is about X-Widgets" (without the quotes) where X-Widgets is usually the last word in the string. There are only X amount of characters allowed in the string, so sometimes "X-Widgets" might be "X-Widge" or "X-Wid" or anything in between. I want to correct this on the page so it always displays as "X-Widgets". Let's assume I have the "X-" to begin with, so I need to test if "W", "Wi", "Wid", "Widg", "Widge", "Widget" are present.

I guess I can use something like


But is there a better way? I tried


but it didn't work, although it seemed like an interesting thing to try. I know there has to be a simple way, but I'm stuck. Thanks!
10:29 pm on Jan 23, 2011 (gmt 0)

5+ Year Member

Actually after scratching my head some more I tried


which seems to work. I'm checking to see if it has any adverse effects that might not be obvious.

Software error:

Can't locate /home/deploy/webmasterworld/code_format-v6.lib in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at decode-post-v6.lib line 27, <THREADDAT> line 4.

For help, please send mail to the webmaster (it@imninjas.com), giving this error message and the time and date of the error.