Solved

use regular expression to change text

Posted on 2014-03-07
6
337 Views
Last Modified: 2014-03-07
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
Comment
Question by:ethar1
  • 3
  • 3
6 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
 

Author Comment

by:ethar1
Comment Utility
Thanks for your reply,
I am using c# VS 2013
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
So the replacement is taking place via C# code, using the Regex class?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:ethar1
Comment Utility
yes
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:ethar1
Comment Utility
Thank you very much
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now