• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

use regular expression to change text

Dear all,
using c# can I change all database rows contains this:
<meaning>xxxxx</meaning>
TO
<meaning text="xxxxx" TextAR=""/>

I prefer to use regular expression.
( I just need the regular expression  implementation or even MS SQL SP)
Thanks,
0
ethar1
Asked:
ethar1
  • 3
  • 3
1 Solution
 
käµfm³d 👽Commented:
Change it where/how? Using Find/Replace in Visual Studio? In C# code? Other?

In any event, the pattern to match would be:

<meaning>([^<]+)</meaning>

Open in new window


...and the replacement would be:

<meaning text="$1" TextAR="" />

Open in new window


...assuming the utility that you are using to execute the replacement supports $n syntax. You might need to exchange "$1" for "\1" instead:

i.e.

<meaning text="\1" TextAR="" />

Open in new window

0
 
ethar1Author Commented:
Thanks for your reply,
I am using c# VS 2013
0
 
käµfm³d 👽Commented:
So the replacement is taking place via C# code, using the Regex class?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ethar1Author Commented:
yes
0
 
käµfm³d 👽Commented:
OK, then the above should work. The code would look like this:

string result = Regex.Replace(original, "<meaning>([^<]+)</meaning>", "<meaning text=\"$1\" TextAR=\"\" />");

Open in new window

0
 
ethar1Author Commented:
Thank you very much
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now