How To Use Regex To Find A Matching String Pattern And Delete It

Feb 4, 2011

I have a table Books with columns BookID, BookSummary, BookAuthor.

What I have stupidly done was to add a link to another url at the end of the BookSummary. Assuming the text is something like this:

This is a book about a love story in World War 2 in Europe. The book is written by Elliot James.

I have added

<a href='http=://XXXXXX'>Buy Book</a> at the end of the text making the final content of BookSummary to be like:

This is a book about a love story in World War 2 in Europe. The book is written by Elliot James.

<a href='http=://XXXXXX'>Buy Book</a>

I now need to write a code (via regex?) to read through each BookSummary, find the <a href='http://XXXXX'>Buy Book</a> and delete it. But the problem is the content in XXX could be anything and I cannot use typical string functions. Can anyone guide me to
achieve this using Regex?

View 7 Replies


Similar Messages:

C# - Regex Pattern For Checking If A String Starts With A Certain Substring?

May 1, 2010

What's the regular expression to check if a string starts with "mailto" or "ftp" or "joe" or...

Now I am using C# and code like this in a big if with many ors:

String.StartsWith("mailto:")
String.StartsWith("ftp")

It looks like a regex would be better for this. Or is there a C# way I am missing here?

View 5 Replies

C# - Populating List Within A For Each Loop After Pattern Matching

Jan 15, 2010

I am trying to assign values I've gathered from a JSON feed to my own type, a class in which I have defined certain fields (properties) to put the JSON elements into, plus elements that are derived from a RegEx pattern matching process. This will then allow me to access the object using LINQ, as I am using a List to hold my objects. There is a foreach loop in my code that loops for each match that my RegEx method finds. I am only interested in the parts of the JSON feed where there is a match. So my own defined class is as such:

//simple field definition class
public class TwitterCollection
{
public string origURL { get; set; }
public string txtDesc { get; set; }
public string imgURL { get; set; }
public string userName { get; set; }
public string createdAt { get; set; }
}

And then I want to populate List in the RegEx Matches loop:

foreach (Match match in matches)
{
GroupCollection groups = match.Groups;
var tc = new List<TwitterCollection>()
{
origURL = groups[0].Value.ToString(),
txtDesc = res.text,
imgUrl = res.profile_image_url,
userName = res.from_user_id,
createdAt = res.created_at,
};
}

The code will then go on to extract and sort the results via Linq to Objects. But compiler won't actually let me create my var tc = new List<TwitterCollection>() because: 'System.Collections.Generic.List' does not contain a definition for 'origURL' ... even though I have defined it. It does not flag an error if I simply write new TwitterCollection but then how do I refer to this in my Linq expression later on??

View 3 Replies

Regex Pattern / How To Use Multiple Instances

Mar 7, 2011

YARPQ - Yet Another Regex Pattern Question:

What I am trying to figure out is how to use a custom delimiter, single character or set of characters, to wrap a block of text inside a larger body of text and then pull that text out via regex. I have successfully done this with a single instance of wrapped text. If I have multiple instances, it blows up. Here is an example.

This would be my text block with the internally wrapped text:

[Code]....

When my current regex runs on this block, the greedy nature gives me a match starting with my first wrapped block delimeter and ending with my second wrapped block end delimeter. So my regex of @"#Delim(.*)#EndDelim" doesn't work in this instance. I am trying to figure out how to exclude the #EndDelim from my grouping. Simply using ([^#EndDelim]*) doesn't work as it tells regex to ignore the individual characters inside the brackets and not the actual word so this breaks if I have any of those characters inside my wrapped block of text.

I am probably making this harder than it needs to be. Does anyone know of a good solution or how to ignore entire words in regex?

View 3 Replies

C# - Regex Pattern / Looking For The X_X Numeric Patterns?

Dec 23, 2010

I will have the following possible strings:

12_3

or

12_3+14_1+16_3-400_2

The numbers could be different, but what I'm looking for are the X_X numeric patterns. However, I need to do a replace that will search for 2_3 and NOT return the 12_3 as a valid match.

The +/-'s are arthemtic symbols, and can be any valid value. They also ARENT required (in the example of the first) .. so, I might want to check a string that just has 12_3, and if I pass in 2_3, it would NOT return a match. Only if I passed in 12_3.

This is for a C# script.

View 2 Replies

Finding Regex Pattern For Phone Number?

Dec 14, 2010

I want regex pattern for phone number as follow.

(111)-111-1111

area code should be entered in paranetheses is mandatory after area code there should be hypen and only three digit should be allowed to enter that is mandatory after 3 digit again hypen should be there that is mandatory and then 4 digit should be enter that is mandatory.

View 4 Replies

State Management :: What Is The Regex Pattern Of Session Id

Sep 7, 2010

asp.net 4.0

I wonder what the Regex pattern for session id is?

View 1 Replies

Regex Pattern For Text With Length Only 9 Or 16 Should Be Allowed?

Jan 27, 2011

I need regex patter for following code.Text with length either 9 0r 16 should only be allowed.

if (txtId.Text.Length != 16 && txtId.Text.Length != 9)

{

//lblError.Text = "Please enter a valid ID";[code]....

View 5 Replies

C# Search Oracle Table Column For Regex Pattern

Jan 20, 2010

I'm trying to build an asp.net page using c# that will query a column in an Oracle database that has 20,000 rows. I want to display all rows that match this regular expression pattern "[]$".(should only have about 5 rows that match this pattern) The version of Oracle we use does not support regex so I need to find a way to do this in c# but I'm not sure how do that.

View 2 Replies

How To Find Matching Values In A Generic List

May 25, 2010

I have anywhere from 5 to 10 generic list in an ASP.NET VB.NET web app. I would like to write a method to pass them all into, and return only the elements they all have in common.

View 2 Replies

Data Controls :: Compare / Find And Display Uncommon (Not Matching) Rows Between Two GridView?

Sep 20, 2015

For ex:

Grid 1

ID Name 

1    aaa
2    bbb
3    ccc

Grid 2

ID Name 

1    aaa
3    ccc 

I want O/P in Grid 3:

2    bbb

View 1 Replies

Web Forms :: Closest String Matching

Mar 6, 2013

I have a model number in one table like 'Q4SD-X24K' and i have a model number in another table like 'q4%' and 'q4sa%d' and q4sd%' and each one contains different pdf links.

and if the user searches for 'Q4SD-X24K' , the closest match i.e q4sd will come and q4sd.pdf has to assign and show up .and i have written one stored proc and i am getting data in a datatable q4,q4sa%d,q4sd in asp.net. how can i match the closest one from this datatable to model number?

View 1 Replies

SQL Server :: Removing Matching String In Multiple Rows?

Dec 8, 2010

I am looking for a better way to update a list of records. I have a string column in my table that contains an array of strings like so:"11112,AAAA1,AAAA2,99998" etc. It is possible that the column could contain one of those values at any position, for instance, these are ALL valid values for the column:

"11112"
"AAAA1,11112"
"11112,AAAA1"
"AAAA1,11112,AAAA2"

I want to write a SQL statement that will remove "11112" from all of the columns when needed. This MUST also remove any leading, trailing, or double comma values that may be left from simply replacing the "11112" with an empty string.As of now, I simply load a SqlDataReader with any records that contain "11112", I replace it with nothing, "", then I fix the string if need be and update it.

View 3 Replies

JavaScript - Format A String Using A String Pattern?

Sep 23, 2010

I have a displayFormat pattern "$###,###,###;-$###,###,###;#"( it can be different too) and I want to reformat the value in the AspxTextbox after deleting the ',' on GotFocus and LostFocus events by calling the following JavaScript function :

[code]....

I have tried to use ASPxFormatter but it is an internal class that is not indented to be used in a user project.Using String.Format('{0:' + displayFormat + '}', parseInt(value))); didn't work too , it threw an exception since String.format doesn't accept this format of pattern,Can you provide a way to reformat my string to any pattern I want not only the one I recite since ?

View 1 Replies

MVC Pattern To Save, Update, Delete.with Detail Code?

Jun 14, 2010

I want MVC pattern to save,update,delete.with detail code

View 3 Replies

MVC :: Design Pattern Of Insert/update/delete Record In The Datagrid?

Mar 13, 2011

i would like to ask about the design pattern of insert/update/delete record in the datagrid.

my page have 3 datagrids, each datagrid display different data.

but when clicking the save/update/delete button, how can i write a good progrmming pattern to perform this action.

any example code for my reference?

View 1 Replies

.net Regex To Find Anchor Tags And Replace Their Url?

May 13, 2010

i'm trying to find all the anchor tags and appending the href value with a variable.
for example

<a href="/page.aspx">link</a> will become <a href="/page.aspx?id=2">
<A hRef='http://www.google.com'><img src='pic.jpg'></a> will become <A hRef='http://www.google.com?id=2'><img src='pic.jpg'></a>

I'm able to match all the anchor tags and href values using regex, then i manually replace the values using string.replace, however i dont think its the efficient way to do this.Is there a solution where i can use something like regex.replace(html,newurlvalue)

View 3 Replies

RegEx To Find The Subdomain Of The Current Link?

Dec 20, 2010

On my page load I want to find out the subdomain of the currently visited site, I got my [URL] into a string, now how can I use RegEx to just retreive "sub" out of the whole string? note that www may and may not be there every time.

View 7 Replies

Web Forms :: Find A Substring (email) In A Large Text Using Regex?

Sep 22, 2010

I want to find a substring (email) in a large text using Regex.

just want to return the first valid email that is found from the input text:

example:

string inputString = "Our email is myname@ourcompany.com.

desired output: myname@ourcompany.com

this is the Regex pattern i've used: ^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$

- is this pattern correct?

Code:

private static void DumpHRefs(string inputString)
{
Match m;
string HRefPattern = @"^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$";
m = Regex.Match(inputString, HRefPattern,
RegexOptions.IgnoreCase | RegexOptions.Compiled);
while (m.Success)
{
Console.WriteLine("Found email " + m.Groups[1] + " at ".......

View 1 Replies

C# - String Manipulation In Regex?

Apr 4, 2011

i have a problem in string manipulation

here is the code

string str = "LDAP://company.com/OU=MyOU1 Control,DC=MyCompany,DC=com";
Regex regex = new Regex("OU=\w+");
var result = regex.Matches(str);
var strList = new List<string>();
foreach (var item in result)
{
strList.Add(item.ToString().Remove(0,3));
}
Console.WriteLine(string.Join("/",strList));

the result i am getting is "MyOU1" instead of getting "MyOU1 Control"

View 2 Replies

Use A Regex To Tell If A String Has 10 Digits?

Jan 6, 2010

I need to find a regex that tests that an input string contains exactly 10 numeric characters, while still allowing other characters in the string.

I'll be stripping all of the non-numeric characters in post processing, but I need the regex for client-side validation.

For example, these should all match:

1234567890
12-456879x54
321225 -1234AAAA
xx1234567890

But these should not:

123456789 (not enough digits)
12345678901 (too many digits)

View 3 Replies

Web Forms :: How To Replace String Using Regex

Jun 16, 2010

I am getting taggings like the following in a string

<color> vocation </color>
<color> elation </color>
<color> sage </color>

you can notice that each tagging differs only in the wordings

vocation
elation
sage

But i want to write a code some thing like this

Regex.Replace(userAx, "<color> vocation </color>",
"<color> </color>"

so that the resulting output does not contain words at the centre.In the above code instead of giving the word vocation exclusively, i have to mention some pattern, so that it will replace all the words instead of doing it for first sentence only.How to modify my code?

View 6 Replies

VS 2010 RegEx Not Splitting String?

Mar 11, 2011

I am trying to get all the words in a string using a regular expression.When I use this expression in javascript, it works, but when I try it in the .Net code I get the whole string.this is my code.Is my regular expression wrong or am I using the wrong method?

Code:
Dim myRegex As New Regex("/([a-zA-Z]){1,1}([a-z])+/g")
Dim str() As String = myRegex.Split(text)

View 3 Replies

C# - How To Check And Extract String Via RegEx

Oct 24, 2010

I am trying to check if a string ends in "@something" and extract "something" from it if it does. For example, I am trying to do something like this:

string temp = "//something//img/@src"
if (temp ends with @xxx)
{
string extracted = (get "src");
...
}
else
{
}

How can I accomplish this?

View 3 Replies

.net - C# - Faster: String.Contains() Or Regex.isMatch()?

Jul 6, 2010

Possible Duplicate: Regex.IsMatch vs string.Contains Which is faster, preferable and why?What the difference in mechanisms between two?I need to search for some values from UserAgent, most of values can be used without wildcards (e.g. if I want to catch cellular phones I search for iPhone instead of *iPhone* wildcards).

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved