How to replace Text with a Regex Regular Expression String in C# .NET Framework

Cloudmersive
1 min readJul 20, 2020

--

Regex can be a great time saver if you know how to use it properly. Unfortunately, it’s the matter of setup that is often what gets in the way, taking a significant amount of time to get working. In this tutorial, we will be covering how to get this down very quickly, and with almost no code required.

First we bring in our library using package manager:

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.2.8

Now we are going to go ahead with calling our function, like so:

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class EditTextReplaceRegexExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new EditTextApi();var request = new ReplaceStringRegexRequest(); // ReplaceStringRegexRequest | Input requesttry{// Replace a string in text with a regex regular expression stringReplaceStringRegexResponse result = apiInstance.EditTextReplaceRegex(request);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditTextApi.EditTextReplaceRegex: " + e.Message );}}}}

And just like that, we are already finished!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet