|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Regex questionI am trying to build a regular expression that will fail to match if the line
starts with a particular phrase, for example I want the match to fail if the line starts with "To Do". In other versions of regular expressions there is the ~ operator that lets me specify this, so I could do something like ~To Do.* and then it will not match any lines that have To Do in them. How do I create something similar in .NET? Thanks, -- Dave E Good book ( and examples ) here:
http://www.apress.com/book/supplementDownload.html?bID=446&sID=2793 Show quote "Dave E" <Da***@discussions.microsoft.com> wrote in message news:52266FE7-11DF-4E03-A17A-D4390732E1F3@microsoft.com... > I am trying to build a regular expression that will fail to match if the line > starts with a particular phrase, for example I want the match to fail if the > line starts with "To Do". In other versions of regular expressions there is > the ~ operator that lets me specify this, so I could do something like ~To > Do.* and then it will not match any lines that have To Do in them. How do I > create something similar in .NET? > > Thanks, > > -- > Dave E Dave E wrote:
> I am trying to build a regular expression that will fail to match if the line ^(?!To Do).*> starts with a particular phrase, for example I want the match to fail if the > line starts with "To Do". In other versions of regular expressions there is > the ~ operator that lets me specify this, so I could do something like ~To > Do.* and then it will not match any lines that have To Do in them. How do I > create something similar in .NET? > > Thanks, > Will match all lines not starting in To Do... If you want all lines not starting in To Do or Fix Me ^(?!To Do|Fix Me).* Set your own options for case insensitive, etc, but it must be set to multiline for this to work. Kris Thanks a lot. That worked great!
-- Show quoteDave E "Kris Erickson" wrote: > Dave E wrote: > > I am trying to build a regular expression that will fail to match if the line > > starts with a particular phrase, for example I want the match to fail if the > > line starts with "To Do". In other versions of regular expressions there is > > the ~ operator that lets me specify this, so I could do something like ~To > > Do.* and then it will not match any lines that have To Do in them. How do I > > create something similar in .NET? > > > > Thanks, > > > > ^(?!To Do).* > > Will match all lines not starting in To Do... If you want all lines not > starting in To Do or Fix Me > > ^(?!To Do|Fix Me).* > > Set your own options for case insensitive, etc, but it must be set to > multiline for this to work. > > Kris > |
|||||||||||||||||||||||