[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Hi-bit characters in regex's



On Sat, 15 Apr 2000 23:10:47 -0500, Kevin van Haaren <kevinv@hockey.net> 
wrote:

>#  whitespace stripped from beginning and end of name
>#	whitespace at end of name is definitely illegal (although toast allows it)
>#	whitespace at beginning of name stripped because i don't like it
...
>	# names can't begin with whitespace
>	$old_string =~ s/^(\s*)//;
>	
>	# names can't end with whitespace
>	$old_string =~ s/(\s*)$//;

Kevin,

If you want to strip spaces from both ends of a string, the following 
will do it for you on a single line:

 $old_string =~ s/^(\s*)(.+)(\s*)$/$2/;

Basically it says "replace the whole string with what's found between the 
second set of brackets".

Nothing to do with the topic, but I just thought you might want to know 
the easier way.

Henry.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org