in reply to Re: regex: help for improvement
in thread regex: help for improvement

I had not seen the de Renstroem ... So the function is even not working as I was expecting.

To treat names with accented letter (say utf8) using your function, I tried this

my ($str) = @_; $str =~ tr/-/ /; #$str =~ tr/a-zA-Z/ /cs; my $new; while ( $str =~ m/\G([\p{isUpper}|\p{isLower}|\s]+)/g ) { $new.=$1; } $str = $new; $str =~ s/(?<=\p{isLower})(?=\p{isUpper})/ /g; $str =~ s/(?:(?<=\s)|(?<=^))(\p{isLower})/\u$1/g; $str =~ s/\s+$//r

but it's not working since any character that is not a letter or a space break the loop and the rest is lost. How can I adapt tr/a-zA-Z/ /cs for unicode character ?

Thanks

F.

Replies are listed 'Best First'.
Re^3: regex: help for improvement
by choroba (Cardinal) on Dec 14, 2018 at 14:35 UTC
    Do you want to replace any sequence of non-letters by a space?
    $str =~ s/\P{isLetter}+/ /g;

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Yes, I think that the way to go !

      Thanks

      F.
Re^3: regex: help for improvement
by AnomalousMonk (Archbishop) on Dec 14, 2018 at 19:21 UTC
    I had not seen the de Renstroem ... So the function is even not working as I was expecting.

    frazap:   WRT the use of Test::More for posing questions (to PerlMonks or to yourself during development!), see also neilwatson's article How to ask better questions using Test::More and sample data. Of course, the essential question you're asking yourself during development is "Does this code work the way I think it works?"


    Give a man a fish:  <%-{-{-{-<

Re^3: regex: help for improvement
by Laurent_R (Canon) on Dec 14, 2018 at 18:16 UTC
    I had not seen the de Renstroem ... So the function is even not working as I was expecting.
    That's where using a testing module such as Test::More, as suggested earlier by hippo, is really useful and handy.