Go Back   openSUSE Forums > Archives > SF Archives > ARCHIVES - Programming & Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read


ARCHIVES - Programming & Scripting A place to discuss website design, programming, shell scripts, etc

 
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 26-Apr-2008, 19:08
davek
Guest
 
Posts: n/a
Default

I am a newbie at RegEx, and was wondering if someone could help me with this little problem.

I have a variety of field names in camel casing:

fieldName

fieldNameAndSomethingElse

etc, etc.

I need to convert them to underscore separated name like so:


field_name

field_name_and_something_else

etc, etc.

Can I do this with regex? How would I?



  #2 (permalink)  
Old 26-Apr-2008, 19:21
ken_yap
Guest
 
Posts: n/a
Default

s/\([a-z]\)\([A-Z]\)/\1_\2/g
  #3 (permalink)  
Old 27-Apr-2008, 05:11
ken_yap
Guest
 
Posts: n/a
Default

Sorry, should be:

s/\([a-z]\)\([A-Z]\)/\1_\L\2/g
  #4 (permalink)  
Old 28-Apr-2008, 16:52
davek
Guest
 
Posts: n/a
Default

Thanks a bunch!
  #5 (permalink)  
Old 30-Apr-2008, 08:18
ChoAkAoto
Guest
 
Posts: n/a
Default

Quote:
s/\([a-z]\)\([A-Z]\)/\1_\2/g
[/b]
Thanks.
 

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2