# RegEx search/replace over multiple files

**URL:** <https://www.ruby-forum.com/t/regex-search-replace-over-multiple-files/96147>\
**Category:** Ruby\
**Created:** [June 26, 2006, 8:17pm UTC](https://www.ruby-forum.com/t/regex-search-replace-over-multiple-files/96147 "2006-06-26T20:17:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![roguerum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/41988e/32.png) [@roguerum](https://www.ruby-forum.com/u/roguerum)\
**Post date:** [June 26, 2006, 8:17pm UTC](https://www.ruby-forum.com/t/regex-search-replace-over-multiple-files/96147/1 "2006-06-26T20:17:32Z")

</div>

## Hoping I might be able to get some help on a regular expression search/replace method that I need to write to modify a bunch of files. I’ve got the pseudocode, but need help with syntax. Here’s an example showing the pattern: Changing this

Class my.foo.bar {

## }

to this

* * *

Package my.foo{  
Class bar {

```
}

```

## }

Here is the pseudo code I came up with  
For each file:

1. Find the line that starts with “class[space]”
2. from that file, strip out everything after [space] to the last  
period on that line, store in myVar without the final period (in this  
case: my.foo)
3. add tab before every line in file
4. insert “Package[space][myVar]{” at beginning of file
5. insert “}” at the very end of file
6. save file and close

It’s my first crack at Ruby, so even if no one can provide me with  
actual code, any insight would really help.

Thanks in advance!

-wakereh
