.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
ADVERTISEMENT
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
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
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
Feb 28, 2009
On a word document I would like to populate same data captured via User Form on multiple locations of a document... i.e. LastName I would like to appear on salutation paragraph and also in the body of the letter... I used REF LastName on the document when using VBA but it seems the same document when it is being populated via a VB application this skim does not work and instead "Error! Reference source not found." appears where ever the REF LastName has been used..
View 3 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 14, 2011
I need a regular expression that will match this pattern (case doesn't matter):066B-E77B-CE41-4279
View 4 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
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
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
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
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
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
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
Apr 21, 2010
sTitle = Regex.Replace(sTitle, @"&w+;", "")
View 1 Replies
Nov 14, 2009
I have a question regarding radio buttons. I am creating a little prog that has three separate radio button groups. After selecting one button in each group, I would like a text box to display a value. The text box value will be a number between 50 and 350 or so.
View 19 Replies
Aug 15, 2009
how i can read multiple lines from a text file to a variable that i can process individually later. Each batch needs to be stored so that i can modify them and then recombine them into a file later.So each "group" starts with the line that begins with 5 and ends with the line that begins with 8, no if we can store the line great, if not then output to a tmp file and merge after completion is ok too.. not sure how to best handle it (hence why i am posting here)I was looking at doing with Regex but this is way over my head right now. So here is what i need to do, and below is the code that processes the groups... not sure how to read the batches in first:So from this input:
101 129984776 12239022378970495730475347 NATIONAL BANK clark county cred
5200HEAVENLY A133016 1880467884PPDPAYROLL 080309090807 1122016060000001
6221224007799238298775 0000201175A13399 $TAX COMPANY 0122016060000001
[code].....
View 2 Replies
Mar 30, 2012
Ok, I have this code... and it works. If I want to add it to say... a checkbox or something of the sort.
Public Sub groupaddarray()
Try
'Alpharetta Staff
If Form1.CheckBox23.Checked = True Then
Dim grp As IADsGroup
[Code]...
My question... how can I double click the listbox, and then it keeps adding these groups to say... another text box, and when I click add groups it will read the textbox, and add multiple groups instead of just the one?
View 2 Replies
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
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
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
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
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
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
Jan 13, 2010
Yes, I've googled. But I must defer to the experts as time to study Regex is not available.
[Code]...
Can these 3 lines be condensed into one line? If so, how? The purpose is to remove all spaces before and after all occurrences of & in a string.
View 3 Replies