tr/[A-Z](w+)/[a-z]$1/ (lowercase the first letter)

tr/[A-Z](w+)/[a-z]$1/ (lowercase the first letter)

3
NewbieNewbie
3

    Apr 12, 2006#1

    I have some Pascal case text ("The QuickTime BrownBear FoxTrot Jumps Over The LazyBone DogMan") that I want to change to Camel case ("the quickTime brownBear foxTrot jumps over the lazyBone dogMan").

    In Perl, I'd do something like:

    $myvar ~= tr/[A-Z](\w+)/[a-z]$1/;

    I'm using PCRE, but I have no idea where I'd put the second have of the tr/// operator....

    Any ideas?

    Thanks,
    dreamwolf

    344
    MasterMaster
    344

      Apr 13, 2006#2

      Hi dreamwolf.

      I don't know too.
      I tried a find ([A-Z])(\w+)
      replace with $1$2
      Which "works". It replaces e.g. Jumps with Jumps, so $1 and $2 is "found" correctly. But how to "lowercase" $1 ?
      Aint there a new helpfile for perl-regexp-style ?

      Hmm, Bego
      Normally using all newest english version incl. each hotfix. Win 10 64 bit

      24
      Basic UserBasic User
      24

        Apr 13, 2006#3

        Hi

        The correct perl syntax would be

        my $string = "The QuickTime BrownBear FoxTrot Jumps Over The LazyBone DogMan";

        $string =~ s/\b(\w)/\L$1/g;

        Unfortunately the UltraEdit Perl Regular expression engine does not recognise the \b (word boundary) character and so this sort of replacement does not work. I will raise a support issue with IDM.

        Cheers

          Re: tr/[A-Z](w+)/[a-z]$1/ (How do I lowercase the first lett

          Apr 13, 2006#4

          To do this in UltraEdit should work using the \L (to lowercase) operation.

          So you should enter this in the Find What:

          \b(\w)

          and the following in the replace with:

          \L$1

          Unfortunately, as I mentioned earlier, UltraEdit has a bug in that it does not recognise the \b character as a word boundary. I have emailed support and hopefully they will deal with this issue. Yet another bug in the Perl regular expression engine.

          344
          MasterMaster
          344

            Apr 13, 2006#5

            Or try this:
            replace
            (\s[A-Z])
            with
            \L$1

            For this example it seems to work, since even a ^ line beginning is interpreted as whitespace :-)

            rds Bego
            Normally using all newest english version incl. each hotfix. Win 10 64 bit

            3
            NewbieNewbie
            3

              Apr 13, 2006#6

              Thanks for the suggestion, Bego! The very beginning of the string (BOF) didn't get changed for me with that, but I was perfectly willing to modify that one character manually. ;)

              Also, piggy-backing on your and Captain's suggestions, I was able to get exactly what I wanted by using \l (lowercase L) instead of \L:

              Code: Select all

              Find:    ([A-Z])(\w*)
              Replace: \l$1$2
              "I, The QuickTime BrownBear FoxTrot Jumps Over The LazyBone DogMan"
              Becomes:
              "i, the quickTime brownBear foxTrot jumps over the lazyBone dogMan"

              Woot!

              dreamwolf

              12
              Basic UserBasic User
              12

                Jun 19, 2006#7

                and how lowercase last characters without first one ?

                example:

                Code: Select all

                ABCDEF
                ABCDEF
                ABCDEF
                into:

                Code: Select all

                Abcdef
                Abcdef
                Abcdef

                3
                NewbieNewbie
                3

                  Jul 08, 2006#8

                  EllE wrote:and how lowercase last characters without first one ?
                  Lowercase "L" ("\l") ensures a single character is lowercase. Uppercase "L" ("\L") capitalizes all letters until it reaches "\E." So, in your case, you can use the principles I have above, but just place a "\L" after the first character. If you also want to be sure the first character is uppercase, use "\u" (same principles apply to "\u" and "\U" as the L's):

                  Code: Select all

                  Find:    ([A-Z])(\w*)
                  Replace: \u$1\L$2
                  That will change both:

                  Code: Select all

                  ABCDEF
                  ABCDEF
                  ABCDEF
                  and

                  Code: Select all

                  abcdef
                  abcdef
                  abcdef
                  into:

                  Code: Select all

                  Abcdef
                  Abcdef
                  Abcdef
                  Sorry it took a while to respond. I don't cruise these forums very often.

                  HTH.

                  dreamwolf