On the Use panel you can generate a source code snippet in your favorite programming language to perform a task of your choice with the regular expression generated by RegexMagic on the Regex panel.
In the default layout and the dual monitor tabbed layout, the Use panel is docked together under a tab with the Regex panel. Click the “Regex, Use” tab near the top of the RegexMagic window to activate the Use panel. In both side by side layouts, the Regex panel is permanently visible.
Press Alt+6 on the keyboard to move keyboard focus to the Use panel, and to make it visible if it was hidden. Or, select the Use item in the View menu. You can access that menu by the View button on the Assistant panel, and by right-clicking on the caption or tab of any panel in RegexMagic.
Once you have generated a regular expression, you are ready to use it. One way is to simply tell RegexMagic to copy the regular expression to the clipboard, so you can paste it into tool or editor where you want to use the regex. If you do this often, you may want to see if it is possible to integrate RegexMagic and the software you use regular expressions with.
If you want to use the regular expression in the source code for an application you are developing, switch to the Use panel in RegexMagic. RegexMagic can generate code snippets in a variety of programming languages that have particularly strong support for regular expressions, or have a popular regular expression library available for them.
Using RegexMagic’s code snippets gives you several major benefits. You don’t have to remember all the details how to use a particular language’s or library’s regex support. Though most languages and libraries have similar capabilities, the actual implementation is quite different. With RegexMagic, you simply select the task you want to accomplish from the list, and RegexMagic generates source code you can readily copy and paste into your code editor or IDE.
For replacement actions, RegexMagic also knows if a particular regex library uses backslashes or dollar signs to insert backreferences into the replacement text. RegexMagic supports both, but most libraries accept only one style.
For languages that support exception handling, RegexMagic’s code snippets also contain
To generate a code snippet, first generate the regular expression for your programming language on the Regex panel. Then switch to the Use panel and select the type of function you want to implement. Some functions are only available for certain languages. E.g. the functions that create an object for repeatedly applying a regular expression are only available in languages with object-oriented regex libraries.
The available functions also depend on the kind of action you defined. Search and extraction functions are listed if you don’t specify an action, search-and-replace functions are listed for replace actions, and splitting functions are listed for split actions.
Most functions allow you to specify certain parameters, such as the variable or string constant you want to use as the subject for the regex operation, the variable to store the results in, the name of the regex or matcher object, etc. RegexMagic does not verify if you entered a valid constant or variable. Whatever you enter is inserted into the code snippet unchanged. The parameters you entered are automatically remembered. For each parameter, the same values are carried over across all the functions, for each language. So you need to enter the names you typically use only once.
RegexMagic keeps the code snippet in sync with your regular expression at all times, even when the regex is syntactically incorrect. The snippet is ready for copying and pasting at all times. If you want, you can edit the snippet in RegexMagic. But remember that your changes will be lost as soon as you regenerate the regular expression.
You can transfer the snippet into your code editor or IDE by clicking the Copy button on the Use tab’s toolbar. This copies the entire snippet to the Windows clipboard, ready for pasting. If you only want to use part of the snippet, either select it and press Ctrl+C on the keyboard to copy it, or select it and then drag-and-drop it with the mouse into your code editor.
RegexMagic ships with source code templates for all of the world’s most popular programming languages. Each template implements a comprehensive set of functions, or things that you can do with your regular expression in the selected programming language.
If the provided functions don’t match your coding style, you can easily edit any of the templates by clicking the Edit button on the toolbar on the Use panel. You can edit or delete the provided functions, and add as many new functions as you like.
You can also create new templates. These can be alternative sets of functions for a programming language already supported by RegexMagic, such as a set of functions specific to a particular development project. You can also create templates for languages not supported by RegexMagic. The only limitation is that you’ll be limited to languages that use one of the regex flavors and string styles already supported by RegexMagic.