Build Regex To Find And Replace Invalid HTML Attributes?

Jul 31, 2009

The sad truth about this post is that I have poor regex skills. I recently came across some code in an old project that I seriously want to do something about. [code]...

View 5 Replies


ADVERTISEMENT

Regex.Replace With A String Of HTML

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

.net - Global RegEx Replace Function To Create HTML From Square Brackets?

Nov 30, 2011

I have some existing code that looks something like this:

[tag:cb cbid="12345" cbwidth="200" cbclassname="calloutbox" cbposition="left"] Lorem ipsum dolor sit amet, consectetur adipiscing elit.
[tag:cb cbid="123" cbwidth="200" cbclass="calloutbox2" cbposition="left"] Suspendisse eleifend enim a magna pretium porttitor.

I need to write a VB .Net global function that will match these [tag:cb] and take the optional parameters and rewrite the string with Html tags.

<div id="12345" width="200" class="calloutbox" position="left">content (based on id)</div>

View 1 Replies

VS 2008 : Regex Find By String With Html?

Mar 12, 2010

#@$#^@ regex have i don't know to use it yet so something like

<img src="find this" alt="Click if
<img src="/validator/11917876/1268416778.gif" alt="Click if

I'm trying to get this src and have PictureBox1.Load[URL] & "regex code" for the captcha to see if over picturebox1

View 6 Replies

Insert Some Html Into A String's Spot So Can Find That Text In A RichTextBox And Replace It?

Mar 14, 2012

I have this code attached to a button

If htmlText.Contains("<frame src='demo.html'/>") Then
htmlText = htmlText.Text.Replace("<frame src="demo.html/>", "<frame src='" &
OpenStory.FileName)

[code].....

View 2 Replies

Concatenating A Variable With A Regex Group Match In Regex.replace?

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

VS 2008 - Regex Replace To Replace Double Quotes With Nothing?

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

Increment Regex Match Using Regex.Replace

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

Forms :: Replace Comma With Regex.Replace?

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

Html - VB Basic RegEx - Save Value From An Input Tag In HTML Source Code

Feb 16, 2011

I am trying save a value from an input tag in some HTML source code. The tag looks like so:

<input name="user_status" value="3" />

I have the page source in a variable (pageSourceCode), and need to work out some regex to get the value (3 in this example). I have this so far: [Code] Which works fine most of the time, however this code is used to process source code from multiple sites (that use the same platform), and sometimes there are other attributes included in the input tag, or they are in a different order, eg:

<input class="someclass" type="hidden" value="3" name="user_status" />

I just dont understand regex enough to cope with these situations.

View 2 Replies

Use Find/Replace To Replace Arbitrary Text Per Line?

Dec 9, 2011

I have a bunch of object variables which are all initialised in their declarations such that:

Private _myObject As New ThisObject("SomeString")

where ThisObject is one of a number of object types, but all are initialised using a string.

I would like to use the Visual Studio Find/Replace dialog box to search for "As New" then replace everything from "As New" to the first set of speech marks with some text such that:

EDIT

My original example could be solved using other methods. This example is more representative of the actual problem:

Private _myObjectA As New ThisObjectA("SomeString")
Private _myObjectLongName As New ThisObjectLongName("SomeString")

[Code]....

View 2 Replies

C# - Prevent HTML Encoding Of Attributes In The Code Behind?

Jul 27, 2011

I have the following in my aspx.

[Code]...

How can I get the < > " characters to render properly?

View 4 Replies

.net - Replace In Regex Match?

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

Regex - Replace [b]xxx[/b] With 'xxx' In Bold

Nov 3, 2010

How can I convert [b]xxx[/b] to <strong>xxx</strong> using VB.NET Regex.Replace()?

View 2 Replies

Regex And Replace Function?

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

Regex.Replace Not Working?

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

RegularExpressions.Regex.Replace

Aug 20, 2009

System.Text.RegularExpressions.Regex.Replace(item.Summary.Text, ????, "")

What would I put in the? to get only the domain from a URL: EG [URL] should turn into "Google".

I don't know how the regex works to make it do that. Would it be like "*/*..*" or something?

View 8 Replies

VS 2010 RegEx Replace?

Sep 26, 2010

Dim ab As String = "aaaextBox1.Text = Regex.Replace(TextBox1.Text, "Dim " + ab + " As String", "aab")That is the code I am using now. Problem is that it's output is only "aab".Is there any way to keep the structure, so it would be "Dim aab As String" instead of only "aab"?

View 2 Replies

How To RegEx Replace Named Groups

Jul 27, 2009

I need to use RegEx.Replace to replace only certain named groups in my input string.

So I might have a pattern like:

"^(?<NoReplace>.+)(?<FirstPeriod>(d{2})|CM|RM|PM|CN|RN){1}(?<LastPeriod>(d{2})|CM|RM|PM|CN|RN){1}((#(?<NumberFormat>[#,.+-%0]+))*)$"

Tokens such as CM, RM are being replaced using Regex.Replace with a MatchEvaluator. However, this should only be replacing characters in the FirstPeriod and LastPeriod groups.

Example input:
"FIELDCNS 01CM"
Desired output:

[Code]....

Is this possible or am I best just pulling out the parts I want to replace and re-assembling afterwards?

View 5 Replies

REGEX Match With Math And Replace

Jun 3, 2011

I'm wanting to search a RTB for all X coordinate values and convert them to SI mm units.

I have two issues: 1. My code is stopping after the first instance of match.success, I'm guessing i'm using nextmatch incorrectly? I have also tried matchcollections with no success.

2. I fear once we get it progressing to the next X value, any multiple X values with the same dimension will be replaced with my replace command, causing the new value to be converted again.

Dim MatchObj As Match = Regex.Match(RichTextBox1.Text, "[Xx](?<X>(d*.{1,1}d{1,4}))(s)*")
If MatchObj.Success Then

[Code]....

View 11 Replies

Regex.Replace Formating A Query?

Nov 18, 2011

I am working in VB.Net and trying to use Regex.Replace to format a string I am using to query Sql. What Im going for is to cut out comments "--". I've found that in most cases the below works for what I need.

string = Regex.Replace(command, "--.*
", "")
and

[code].....

View 2 Replies

Replace Line Breaks Using Regex?

Aug 23, 2011

How can I replace all types of line breaks (CR, LF and CrLf) using Regex?

I´ve tried different combinations of "
" and "
" but none finds them all.

formatedString = System.Text.RegularExpressions.Regex.Replace(text, "

", "[Exp 1]")

The following code does the job but it bugs my that I can´t seem to replace the Line Feed using Regexp.

[Code]....

View 3 Replies

Translate This C# Line For Doing A RegEx.replace To VB?

Apr 21, 2010

sTitle = Regex.Replace(sTitle, @"&w+;", "")

View 1 Replies

Build A Regex To Detect Words Not Adjacent To Or Enclosed In Braces?

Jan 1, 2012

I am stuck in a problem with an application. I have following lines of text :1) hi {my|your|his} name is {stacker|monster|overflow}2) hi {my|your|his} job can be to {stacker|monster|overflow}3) hi {my|your|his} car {stacker|monster|overflow}What I want :on the click of a button select and replace those words which do not have { or } just before or after the word i.e. in line 1 or 3 we do not have any such word. In line 2 we have "can" and "be".

View 1 Replies

.net - Replace Multiple Captured Groups In Regex?

Feb 9, 2012

VB2005: I've been looking at regex for some hours now and cant seem to get my head around the .Replace for my case. I'm looking for two fields and then I want to replace those fields with new values. So my string looks like so:

[Code]...

What do I put in MyRegexReplace? This is a simple two value replace but Im going to have possibly more so was thinking there has got to be a way to do this but need .

View 1 Replies

Calculate Inside Regex.replace Function?

May 21, 2010

I am trying to perform calculations on Regex substrings. I would like to do something like (see $2)

lblResult.Text = reg_exp.Replace(txtInput.Text, "$1" & "$2" * 0.039 & "$3" & "$4" & "$5")

I can only do this like:

For Each RxMatch In reg_exp.Matches(Me.txtInput.Text)
Me.lblResult.Text = Me.lblResult.Text & _
RxMatch.Groups.Item(1).ToString & _
Math.Round(CDbl(RxMatch.Groups.Item(2).ToString) * 0.03937, 4) & _

[code]....

View 3 Replies

Extract And Replace Named Group Regex?

Dec 29, 2010

I was able to extract href value of anchors in an html string. Now, what I want to achieve is extract the href value and replace this value with a new GUID. I need to return both the replaced html string and list of extracted href value and it's corresponding GUID.

My existing code is like:
Dim sPattern As String = "<a[^>]*hrefs*=s*((""(?<URL>[^""]*)"")|('(?<URL>[^']*)')|(?<URL>[^s]* ))"

[code]......

View 1 Replies

RegEx - Parse CSV File And Replace Certain Characters

Sep 2, 2010

I've used regular expressions in the past. I have an app that parses a .csv file and replaces certain characters (commas). Here's an example..
item1, item2, item3, fruits are apples, oranges, grapes. Squash is a vegetable, not a fruit.
What my app does is search each line between character1 and character18 and replace all "," with "~". How this is done through regular expressions?

View 2 Replies

Replace Characters Inside Parenthesis Using Regex?

Sep 30, 2010

To search a pattern containing parenthesis, they must be escaped using backslashes. So to search for (Streetname) you must use (Streetname). If you don't use , whatever is between () will be retained and available for reference through the variables $1, $2 etc... Exemple, in the sentence "It's worth noting that (StreetName) can be anything...(Post), (TreeStump)", $1=StreetName, $2=Post, $3=TreeStump

[Code]....

View 3 Replies

VS 2008 Regex Replace Upper Case?

Feb 4, 2010

For example, I want to match <Tag or <TAG and replace to <tag

Here's what I did(which obviously did not work): tmp = Regex.Replace(tmp, "<(.*)", LCase("$1"))

Just wondering what are some good ways to do this?

View 8 Replies







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