Forum Discussion
Regex expression for replacing particular symbols in text- ®and ™
Hi,
I'm wanting to create a regular expression which will take a string, and if that string includes symbols ® and ™ I want to then wrap those symbols with a <Sup> tag.
e.g. "hello® this is a test™"
outcome = hello <sup>®</sup> this is a test <sup>™</sup>
Can anyone help?
Thanks
1 Reply
- AddWebSolutionBrass Contributor
Hi Aaron-92 ,
Thanks for posting your issue here.
Here's how you can implement it within an ASP.NET Core controller action:
using Microsoft.AspNetCore.Mvc;
using System.Text.RegularExpressions;
namespace YourNamespace.Controllers
{
public class YourController : Controller
{
public IActionResult YourAction()
{
string input = "hello® this is a test™";
string pattern = "(®|™)";
string replacement = "<sup>$1</sup>";
string result = Regex.Replace(input, pattern, replacement);
ViewBag.Result = result; // Store the result in ViewBag or pass it to your view model
return View(); // Return the view where you want to display the result
}
}
}
Note :
- Make sure to replace Your Namespace, Your Controller, and Your Action with your actual application's namespaces, controller name, and action name.Best Regards,
AddWebSolution