Solved

use regular expression to change text

Posted on 2014-03-07
6
345 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL Sever Import/export problem 7 45
Rebooting Witness SQL Server 2 25
disk usage reporting tools 27 50
Access #Deleted data 20 39
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

735 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