Convert The Regex Match to Uppercase or Lowercase

This example demonstrates how you can prepare a search-and-replace action with RegexMagic to convert the regular expression match to uppercase or lowercase. This only works with applications that support case conversion as part of their replacement text syntax. If your application does not then you’ll get an error when you click the Generate button on the Regex panel explaining case conversion is not supported.

We’ll generate a regex that matches GUIDs case insensitively and prepare a replacement to convert them to all uppercase. You can find this example as “Action: convert match case” in the RegexMagic library.

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. On the Samples panel, paste in one new sample that has a block of valid and a block of invalid GUIDs:
    {d1a5279d-B27D-4CD4-A05E-EFDD53D08E8D}
    {594ABD08-C02C-4827-8ABF-a128006848a3}
    {99367d71-08ad-4aec-8e73-55ae151614f9}
    {5ba3bba3-729a-4717-88c1-b7c4b7ba80db}
  3. Select the first GUID {d1a5279d-B27D-4CD4-A05E-EFDD53D08E8D} in the sample text.
  4. Click the Mark button. RegexMagic automatically adds a field using the GUID pattern. It automatically detects the GUID has braces, hyphens, and is case insensitive and sets those options.
  5. Set the “field validation mode” to “strict”.
  6. On the Action panel, select “convert match case” in the “action to take” drop-down list.



  7. Set “case conversion” to “all uppercase”.
  8. On the Regex panel, select Perl as your application and click the Generate button. You’ll get a regex that matches a GUID case insensitively along with this replacement text:
    \U$&

Related Examples

Reference