Microsoft's .NET framework provides a solid implementation of regular expressions. If you're using Delphi Prism (also known as Oxygene for .NET), or the Delphi for .NET compiler that CodeGear shipped with Delphi 8, 2005, 2006, and 2007, then simply add System.Text.RegularExpressions to the uses clause. You can then use all of the the regex classes from the .NET Common Language Runtime.
While .NET's regex support is solid, Microsoft's regex documentation is very poor. And it does not cover the Delphi language either. Fortunately, RegexBuddy makes it very easy to use the power of regexes in your Delphi Prism and Delphi for .NET source code.
See How Easy Coding with Regexes Can Be
First, use RegexBuddy to define a regex or retrieve a regexp saved in a RegexBuddy library. Rely on RegexBuddy's clear regex analysis, which is constantly updated as you build the pattern, rather than dealing with the cryptic regex syntax on your own. Detailed help on that syntax is always only a click away.
If you copied a regex written for another programming language, simply paste it into RegexBuddy, select the original language, and then convert the regex to the specific version of Delphi you're working with. If you're developing a component that needs to work with multiple versions of Delphi, compare your regex between those Delphi versions to make sure it will work exactly the same with all of them. RegexBuddy supports all Delphi versions, including the latest 10.2 Tokyo.
If you created a new regular expression, test and debug it in RegexBuddy before using it in your Delphi source code. Test each regex in RegexBuddy's safe sandbox without risking precious data. Quickly apply the regex to a wide variety of input and sample data, without having to produce that input through your application.
Finally, let RegexBuddy generate a source code snippet that you can copy and paste directly into the RAD Studio IDE, or whichever Delphi code editor you use. Choose what you want to use the regex for and a fully functional code snippet is ready. You can change the names of variables and parameters to suit your naming style or the current situation, which RegexBuddy automatically remembers. You can generate code snippets that use the RegularExpressions unit or the RegularExprssionsCore unit in Delphi XE and later. You can also generate snippets using the classic TPerlRegEx component for earlier Delphi versions. You can even generate code snippets for Delphi Prism (Oxygene) or the discontinued Delphi for .NET compiler using the .NET regex classes.
While TRegEx, TPerlRegEx, and the .NET Regex classes are all quite different, you don't have to remember the details of how to use either of them. Just tell RegexBuddy what you want to do, and you will get the proper the proper code for your Delphi version and variant straight away. Anything can be done: testing a string for a match, extracting search matches, validating input, search-and-replace, splitting a string, etc.
|Using the PCRE-based TRegEx class in Delphi|
|Using the .NET’s Regex classes in Delphi Prism|