views:

978

answers:

1

Hi all,

First post, so here goes. I'm writing a script that does intelligent search and replace on a file tree. Essentially, the script gets each file's contents into a buffer string and performs a match with a pre-defined pattern, in this case the pattern is /^[^\r\n]*(vendor)[^\r\n]*$/im. The pattern should find any case-insensitive forms of "vendor" and give me the entire line that was matched. I need to see the whole line in order to determine whether or not to replace the occurrence. This pattern performs well for any number of separate line occurences in a given file.

However, if there are multiple occurrences on a given line, the pattern will only match one of those occurrences, and skip the others. I'm trying to determine if I need to have a second pattern to do additional searching on the matched line, or if I can accomplish this purpose with a single pattern that does all of the above.

Just a sample of what I'm hoping to produce. An example of a single line, multi-occurrence match:

Enthusiastically revolutionize web-enabled VENDOR potentialities vendors installed base e-tailers.

I would like to output something similar to this (again, the ouput isn't the issue here, it's whether or not I can match it all with one pattern):

Multiple occurrences in line: || Enthusiastically revolutionize web-enabled VENDOR potentialities vendors installed base e-tailers. ||

Replace? (y,n,q) || ...abled VENDOR poten... ||

Replace? (y,n,q) || ...ties vendors insta... ||

Please let me know if I am unclear on my objective. Thanks for any help and response to this!

+1  A: 

If you are using

/^[^\r\n]*(vendor)[^\r\n]*$/im

I would suggest adding the g (global) operator

/^[^\r\n]*(vendor)[^\r\n]*$/img
Ben Doom