Removing underscores only from CSS class descriptors

Find, replace, find in files, replace in files, regular expressions

Removing underscores only from CSS class descriptors

Postby mkleiman » Tue Apr 11, 2006 1:28 pm

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
User avatar
mkleiman
Newbie
 
Posts: 5
Joined: Sun Apr 09, 2006 11:00 pm

Re: Removing underscores only from CSS class descriptors

Postby cjard » Tue Apr 11, 2006 2:17 pm

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...
User avatar
cjard
Newbie
 
Posts: 4
Joined: Mon Apr 10, 2006 11:00 pm

Re: Removing underscores only from CSS class descriptors

Postby mkleiman » Wed Apr 12, 2006 12:51 pm

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!
User avatar
mkleiman
Newbie
 
Posts: 5
Joined: Sun Apr 09, 2006 11:00 pm

Re: Removing underscores only from CSS class descriptors

Postby Captain » Thu Apr 13, 2006 6:55 am

Hi

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

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

Replace with

.$1$2

cheers
User avatar
Captain
Basic User
Basic User
 
Posts: 27
Joined: Tue Jul 26, 2005 11:00 pm

Re: Removing underscores only from CSS class descriptors

Postby mkleiman » Tue Apr 18, 2006 3:15 pm

Hey there,

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

Thanks all for the help tho!

Cheers
User avatar
mkleiman
Newbie
 
Posts: 5
Joined: Sun Apr 09, 2006 11:00 pm

Re: Removing underscores only from CSS class descriptors

Postby scallanh » Tue Apr 18, 2006 5:03 pm

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.
User avatar
scallanh
Basic User
Basic User
 
Posts: 31
Joined: Mon Oct 24, 2005 11:00 pm


Return to Find/Replace/Regular Expressions