.net - Replace Content In A String Based On Regex.Matches MatchCollection?
Mar 5, 2009
I've been working on this RegEx for the past day or so and I think I have it worked out so that it returns the data I want. First a little background.I have a content editor that users will be able to edit web pages. They can format text, add links, etc.. standard content editor stuff. When they click save, the editor provides the ability to get the content (editor.Content) and put it into a string. What I want to do is get any links (<a> tags) and find out if they are internal or external links and if they are PDF files.
Here is the Expression I've come up with:
<a[^<>]*hrefs*=s*[""'](?<domain>https?://[^/s'""]*)*/?(?<path>/?[^s""]+?)?[[>""']
With this, I am able to separate the domain (if it has one) and the path out. Then, I loop through the matches...
dim matchColl as MatchCollection = Regex.Matches(editorContent, regExString)
For Each m as Match in matchColl
If m.Groups("domain").value <> myInternalDomain and m.Groups("domain").value <> "" then
'this is an external domain... do some stuff
[code]....
My question is this... the parts where I 'do some stuff' to the values, what would be the best way to get that back into my 'editorContent' string? I could probably put the editorContent into a StringBuilder and do a whole bunch of replaces on it, but is that very efficient?So, for example, with the PDF, I want to specify that it open in a new window (target="_blank") and for the external URL, add some javascript code into the onclick attribute.
View 1 Replies
ADVERTISEMENT
Jan 30, 2012
i have to search a string for a few words eg, dog, cat, lion but i want regex to fail if lizard is found in the string even if it contains cat, dog or lion.ismatch(pass) "dog|cat|lion" "This is not your average cat!"ismatch (fail) ??? "This is not your average cat! It's a lizard."??? - here the regex statement is unknown word spaces and boundaries or lower/uppercase is not a concern. I run the string through Replace(" ", "").Trim(" ").ToLower before handover to Regex.
View 3 Replies
Jun 24, 2011
I have a string that contains multiple instances of a dollar sign followed by a positive number. I need to grab each instance out using regex. Here's an example of a string:
"This that $1 who $2" Here's what I have so far using vb.net: Dim wordSplitMatches As Match = Regex.Match("This that $1 who $2", "($d+)+")This works great for grabbing the $1 but how do I set it up so that I get multiple groups with all the matches in?
[Code]...
View 1 Replies
Jun 25, 2009
I have a long string of HTML code that contains several quotes around objects in the string. I have a Regex.Replace() function to change the "img src" tag, due to the way its stored in a database.
Here is my string: <p><strong><u><font color="#cc0099">RICH TEXT BOLD UNDERLINE. PICTURE TO APPEAR BELOW</font></u></strong></p><p><strong><u><font color="#cc0099"/></u></strong></p><p><img src="/inlineimages/WorkOrder/6/1245981403232.jpg"/> </p><p /><p>W00T!</p>
[Code].....
Notice how the "<font color=" has single quotes around its value, and "<img src=" has single quotes, with a double quote jammed in between?
Also, is there an automated way to go from my initial string, to the "Dim input As String" I created? I had to manually type that out, editing the quotes just to try and make it work.
View 6 Replies
Mar 1, 2012
I want to select a random space in a string and replace it with a word (%word%) but there is a problem. The position cannot be fixed as i want it to be inserted at a random break. Few things which iam considering :
1)break the string at a space and merge it with the word
2) find a random space and replace it with the word. I like this point and so far all i have is break the selectedtext into string array and then iterate over each line. But i don't know how to find a random string position? Any short and sweet code please?
If (rtfArticle.SelectedText.Length > 0) Then
Dim strArray As String() = rtfArticle.SelectedText.Split(New Char() {ChrW(10)})
For Each str3 As String In strArray
[code]....
View 2 Replies
Oct 6, 2010
Using VB or C#, I am getting a string of variable length from the database. This information is sensitive information that only certain users will be able to see.I have two cases that will use the same logic (I think).scenario 1: replace all characters with xscenario 2: replace all characters with x except the last 4 characters (assume length > 4 - this check is being done).I thought that this would be easiest using Regex.Replace(input, pattern, replacestring). As opposed to a lot of string handling with substrings and forcing a length of 'x's.
View 2 Replies
May 5, 2009
I have text file with a row like this:
[Code]...
View 2 Replies
Jul 20, 2009
I'm trying to replace all the carriage return characters in a string obtained from a multi line text box in a Windows Form with the string ", <BR>" so that when I use the string in some HTML it displays correctly.
Function Blah(ByVal strInput As String) As String
Dim rexCR As Object
rexCR = CreateObject("VBScript.RegExp")
[code]....
View 5 Replies
Jun 28, 2010
[code]I am trying to return all number values that match the regex yet this only returns the first one when there are more after it.
View 5 Replies
Jan 7, 2010
Trying to parse this and return the following 3 items: [code] Using this regex expression below I get the matches, but drop the leading "-" at the front of each grouping. I get the "-" in the middle of the group though. [code]
View 2 Replies
Mar 12, 2012
I am working on my application to extract the value from my php page using with the regex pattern. I can extract the value using with the mystrings1 tags with no problem, but I can't be able to extract mystrings1 and mystrings2 tags in the same line.
[Code]...
View 2 Replies
Feb 17, 2010
I'm searching through an html page and I want to put all of the Regex matches into an array? How would I go about doing this? I see the Regex.Matches but I can't quite understand how to use it an MSDN sucks when it comes to explaining it.
View 4 Replies
Jan 9, 2012
I want to create a string of values separated by commas from a MatchCollection. So far the only way I have been able to make it work is by using a �For To� loop to load an string array one at a time then joining the array. IE is there any way to join the value properties of each match object?
View 6 Replies
Feb 1, 2011
I am just can't get my head around this.I've got this Regex:
(?<=Photo:)(.+?)(?=Stock)|(?<=Stock Code:)(.+?)(?=Make:)|(?<=Make:)(.+?)(?=Model:)|(?<=Model:)(.+?)(?=Year:)|(?<=Year:)(.+?)(?=Price:)|(?<=Price:)(.+?)(?=Description:)|(?<=Description:)(.+?)(?=Photo:)|(?<=Description:)(.+?)(?=Page:)
[code]....
View 2 Replies
Mar 9, 2011
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.web.com")
Dim response As System.Net.HttpWebResponse = request.GetResponse
[code].....
View 2 Replies
Apr 5, 2012
I am having an issue where I am using regex.Replace to replace part of a string. The basic idea is that I want to capture the beginning of the string then replace the end of the string with a value from code. For an example pretend I have a string that says "Test Number " followed by number and I want to increment that number. I capture the "Test Number " but when I try to concatenate that capture with the new number it treats the capture ($1) as a literal and replaces the entire string with $1[new number].
[code]...
This will output "We are on Test Number 2", as expected. how I can use a variable in the replacement string portion of the Regex.Replace when including a captured group?
View 1 Replies
Oct 24, 2009
i have a listbox w/items. that when running code, the rtb, if it contains a listbox item, it replaces it.. no problem there..the problem i'm facing is that if i have the word "To" in the listbox, by using .contains, when running text in rtb, if i have "DeskTop" as a word in rtb, it ends up replacing the "To" in "DeskTop"..
i have tried the intellisense menu to the limit on finding something other than .contains to use in order to only replace if it matches exactly the item in the listbox. no luck. ;o/
View 10 Replies
Aug 22, 2010
Rename files in a folder who's name matches a regex pattern ?[code]...
View 3 Replies
Apr 3, 2012
Question:Given a SQL string like
CREATE VIEW TestView AS
SELECT value1, value2
FROM TABLE_0[code]...........
for each strObjectName in tables, to check whether or not the view depends on this object.But this fails on table_12 (and results in cyclic dependencies) for example, because tables contains "table_1". Aaargh.I need a regex that can check if the view definition contains a function name, table-valued function or another view...
(
For checking with
System.Text.RegularExpressions.Regex.IsMatch([code].....
But it fails, plus it doesn't account for object names embraced in brackets, like
"[TABLE_NAME]"
View 3 Replies
Jul 13, 2009
I am trying to think of a regex replace to replace double quotes with nothing. Example:
hello("hi there") would become hello(hi there)
"hi" would become hi
"example "3" would become example "3
-edit Maybe an easier way to explain this is, replace all " that do not have a backslash before them.
View 6 Replies
Jun 21, 2012
I'm creating a program in VB.NET to output multiple images. Some images will have the same file name. If there is multiple files with the same name I want to add "_1_" to the end of the file name. If the "_1_" file already exists I want to increment the 1 to be "_2_". If this file already exists I want to continue incrementing the number ultil it doesn't exist. So for example "filename", filename_1_", "filename_2_", etc. Here is the code that I have tried
[Code]...
View 1 Replies
Mar 10, 2009
I am trying to filter out all unwanted characters from a string. All I want in the string is letters A-Z, numbers 0-9 as well as comma (,) plus (+) and quotes (").I figured how to do the letters and numbers, but the 3 special characters are giving me a problem. I also tried with the Chr(34) equivelant for the " sign, but no luck, as and " or , messes up the way the code is read. Here�s what I have so far, but it only works for A-Z and 0-9:
STR = System.Text.RegularExpressions.Regex.Replace(STR, "[^A-Z, 0-9, Chr(43) ]", "")
View 4 Replies
Jul 16, 2011
I have a database with a table that is a child to many other tables. I am using this child table as a datasource for a datagridview. I am using comboboxes to display specific fields in any parent tables, instead of the user seeing the foreign key. Everything is fine. However, I would like to filter the BindingSource based on text matches between any of the fields in the child table and the corresponding fields of the parent tables.
[Code]...
View 5 Replies
Jun 22, 2010
I got an app, which receives data via a R232 port, convert it to a string and on the other side I got a database, where the strings are saved. How can I find a way to compare the string with all strings in one database column and get back the another stringform the same row in this database. I never programmed a database
View 1 Replies
Oct 2, 2009
Trying to parse this and return the following 3 items:
-30.25 31.46 -27.46 31.74
-24.57 32.03 -16.86 32.88
-13.82 33.19 -9.69 33.62
Using this regex expression below I get the matches, but drop the leading "-" at the front of each grouping. I get the "-" in the middle of the group though. Here is the expression I currently use.
Dim regex As New System.Text.RegularExpressions.Regex("{0,1}d{1,2}.{0,1}d{0,2}{1}-{0,1}d{1,2}.{0,1}d{0,2}s{1}-{0,1}d{1,2}.{0,1}d{0,2}s{1}-{0,1}d{1,2}.{0,1}d{0,2}, RegexOptions.Singleline)
[code]......
View 1 Replies
Dec 5, 2010
I want to get tags content in a string with regular expression. I wrote it for just one line. When the content changed into some lines from one line, Regex will never do pattern on the tag. I choose RegexOptions.Multiline + RegexOptions.Singleline for finding options.My pattern in low level: (>)[ a-z A-z 0-9 ]*(</)
View 2 Replies
Mar 26, 2012
I'm using the following VB.net Code to find phone numbers in HTML and make them "clickable":
Regex.Replace(pDisp.Document.Body.innerHTML, "([0-9+ ]{3,6}[s]{1,1}[0123456789 -/]{4,15})", "<a href=http://DIAL/$1>$1</a>")
There appears an issue if the numbers contain white spaces, for example:
089 12233 455
This will be replaced with:
<a href=http://DIAL/089 12233 455>089 12233 455</a>
Is there a way to get
<a href=http://DIAL/08912233455>089 12233 455</a>
instead?
View 3 Replies
Nov 3, 2010
How can I convert [b]xxx[/b] to <strong>xxx</strong> using VB.NET Regex.Replace()?
View 2 Replies
Jun 23, 2009
I have a text file like this
4.5 28 Red (T1 ) [1 12.86 53.8] 229111 -28275 198452 -1309 | 11.0 28 Red (2 13.10 04.0) [T1 ] 130611 2948 229111 28275
1.5 28 Blue (T2 ) [1 07.06 59.1] 191611 51225 190456 39339 |
[code].....
View 2 Replies
Aug 15, 2011
I am trying to replace text in my xsl file. I have to replace all the http and https. But I can leave any links that start with <a href>
Ie; http://www.google.com has to replaced. But < a href="google.com">google.com</a> has to remain as it is.
I am using regex to find all the http(s) and a hrefs in the text. I am struck here.
My code is,
Dim href As New Regex("(<a.*?>.*?</a>)", RegexOptions.IgnoreCase)
Dim hrefs As New Regex("http(s)?://([w+?.w+])+([a-zA-Z0-9~!@#$\%^&*()_-=+\/?.:;',]*)?", RegexOptions.IgnoreCase)
[Code].....
I am trying to use Regex.Replace to replace my https. But I am unable to write the evaluate function.
My regex.replace replaces all the values with a single value.
View 4 Replies