Removing underscores only from CSS class descriptors

Removing underscores only from CSS class descriptors

5
NewbieNewbie
5

    Apr 11, 2006#1

    Basically I want to remove any underscores that have been coded into CSS classes, so :

    .test_left

    Would become

    .testleft

    But would leave other underscore untouched, for instance href links with _blank targets and the like, so as long as the underscore is preceeded by a word and a period

    3
    NewbieNewbie
    3

      Apr 11, 2006#2

      find a period (followed by zero or more word characters) followed by an underscore (followed by 0 or more of any character matched pessimistically) followed by a word boundary

      replace with a period $1 $2



      you might have to repeatedly run this replacement as it only removes the first underscore in any identifier

      \.(\w*)_(.*?)\b

      .$1$2



      try that...

      5
      NewbieNewbie
      5

        Apr 12, 2006#3

        Hey there, thanks for the tip, unfortunatley this doesn't even find a string. I tried with UNIX both on and off just to ensure that wasn't affecting anythihg, but didn't seem to work. If you have a solution using UltraEdit RegEx that would be superb! :)

        Thanks for the aisstance anyways!

        24
        Basic UserBasic User
        24

          Apr 13, 2006#4

          Hi

          Using the Perl regular expression engine you would do the following:

          Find what: .(\w+)_(\w+)

          Replace with

          .$1$2

          cheers

          5
          NewbieNewbie
          5

            Apr 18, 2006#5

            Hey there,

            I must be doing something wrong because none of those solutions work unfortunately :(

            Thanks all for the help tho!

            Cheers

            29
            Basic UserBasic User
            29

              Apr 18, 2006#6

              You're probably not doing anything wrong. I think the reason those suggested solutions don't work is because "\w" matches underscores (it's equivalent to "[a-zA-Z0-9_]"). Also the period needs to be escaped because it normally means "any single character".

              Find:
              (\.[a-zA-Z][-a-zA-Z0-9]*)_([-a-zA-Z0-9]+)(\b|_)

              Replace:
              $1$2

              That should remove up to two underscores from class names. For classes with more than two underscores you'll have to run the search/replace again.