Re: how to add a space using a regex
- From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@xxxxxxxxxxxxx>
- Date: Wed, 31 Aug 2005 11:16:55 +0200
anno4000@xxxxxxxxxxxxxxxxxxxxxxx (Anno Siegel) wrote:
> Jerry Preston <g-preston1@xxxxxx> wrote in comp.lang.perl.misc:
>> What I want to do is add a space between one's name when the are
>> like the following:
>>
>> $name1 = "FirstLast:";
>>
>> I want change $name1 = "First Last";
>>
>> and
>>
>> $name1 = "FirstMiddleLast:";
>>
>> I want change $name1 = "First Middle Last";
>>
>> To be able to add spaces for either "FirstLast:" or
>> "FirstMiddleLast:" with the same regex?
>
> A regex doesn't change a string, but a substitution (one part of
> which is a regex) does.
>
> Can you insert spaces in either "FirstLast:" or "FirstMiddleLast:"
> with the same substitution? That would depend on how you intend
> to recognize the parts of the nname. You have said nothing about
> that.
>
> Here is a substitution that inserts a space whereever a capital
> letter immediately follows a lower-case one:
>
> s/([[:lower:]])([[:upper:]])/$1 $2/g;
>
> but that would mis-handle names like "McBarren".
I suggest that two letter first names are quite rare, which leads to
an obvious adjustment of your regex. Still not perfect, but much
closer.
--
Cheers,
Bernard
.
- Follow-Ups:
- Re: how to add a space using a regex
- From: Matt Garrish
- Re: how to add a space using a regex
- From: John Bokma
- Re: how to add a space using a regex
- References:
- how to add a space using a regex
- From: Jerry Preston
- Re: how to add a space using a regex
- From: Anno Siegel
- how to add a space using a regex
- Prev by Date: Re: Perl match problem
- Next by Date: Re: how to add a space using a regex
- Previous by thread: Re: how to add a space using a regex
- Next by thread: Re: how to add a space using a regex
- Index(es):
Relevant Pages
|