Solved

use regular expression to change text

Posted on 2014-03-07
6
343 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 75

Expert Comment

by:käµfm³d 👽
ID: 39912865
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
ID: 39912880
Thanks for your reply,
I am using c# VS 2013
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39912917
So the replacement is taking place via C# code, using the Regex class?
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:ethar1
ID: 39912927
yes
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39912935
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
ID: 39913076
Thank you very much
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

856 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