I n开发者_如何学JAVAeed to find all strings without a given string before it.
For Instance:
Find: "someValue"
**All results with "function(" before them should be ignored
The Visual Studio regular expression would find this:
value = someValue
And Ignore something looking like this:
function(someValue)
What is the best way to go about this?
Thanks for the help!
You could use negative look-behind:
(?<!function\()someValue
You said
The Visual Studio regular expression would find this:
Combined with the title of your question, that makes me think you're trying to do something in a search and replace dialog in Visual Studio, rather than using a regex in an application.
If that's the case, then I think you might be out of luck; Visual Studio's regular expressions aren't very powerful, and they have a rather odd syntax that doesn't seem to be used anywhere else!
My advice would be to either use a different text editor, or use the regex described by SilentGhost in a .NET application (or PowerShell script) to do the replacement for you. When I need to do regex stuff in an editor and Studio doesn't cut it, I tend to use TextPad. It's not very pretty, but it's powerful and has great macro support.
Incidentally, if you want to use PowerShell to do it, this will search foo.js
, and copy the output to fooNew.js
:
(get-content D:\junk\foo.js) -replace
'(?<!function\()someValue', 'someOtherValue' > D:\junk\fooNew.js
精彩评论