Regex - Matching And Replacing The Contents Of Multiple Overlapping Sets Of Brackets In A String?
Jun 5, 2011
I am using vb.net to parse my own basic scripting language, sample below. I am a bit stuck trying to deal with the 2 separate types of nested brackets.
Assuming name = Sam
Assuming timeFormat = hh:mm:ss
Assuming time() is a function that takes a format string but
has a default value and returns a string.
[code]....
I could in theory change the syntax of the script completely but I would rather not. It is designed like this to enable strings without quotes because it will be included in an XML file and quotes in that context were getting messy and very prone to errors and readability issues. If this fails I could redesign using something other than quotes to mark out strings but I would rather use this method.
Preferably, unless there is some other way I am not aware of, I would like to do this using regex. I am aware that the standard regex is not really capable of this but I believe this is possible using MatchEvaluators in vb.net and some form of recursion based replacing. However I have not been able to get my head around it for the last day or so, possibly because it is hugely difficult, possibly because I am ill, or possibly because I am plain thick. I do have the following regex for parts of it.
Detecting the parentheses: (w*?)((.*?))(?=[^(+)]*((|$))
Detecting the square brackets: [[(.*?)]](?=[^[+]]*([[|$))
View 2 Replies
ADVERTISEMENT
Mar 28, 2012
I've got an issue with a program I am writing. The specific issue is replacing characters in a parent string by finding, and matching, specific characters within it that are parsed from an external xml file. It's for a chat-like client.Here's the 2 classes I am using to pull the emote strings, titles, and id from external XML:
Imports System.Text.RegularExpressions
Imports System.Xml.Serialization
Public Class emote
[code].....
View 1 Replies
Dec 20, 2011
I'm sure this is simple and I'll probably be embarrassed to have this question in my profile but I can't seem to get this Regex correct.
I'm tring to extract just the digits from the last group of the following string:
Properties[1].Securitymeasures[14].AdditionalSecurityType
so I want to have a regex that will return 14
The Regex I have come up with is:
[(d)+]
However - the match is returning "[14]" - including the brackets and I do not understand why. I have surrounded the d with parenthesis which should mean that this is the data I want to capture.
View 2 Replies
Oct 24, 2011
I have a program that goes through SQL statements, identifying component parts with a space. eg: -
SELECT * FROM tblSales WHERE CustomerID=10 AND Year=2011
Would produce the following as separate components: -
"SELECT","*","FROM","tblSales","WHERE","CustomerID=10","AND" and "Year=2011"
The problem I have however is the use of spaces within values eg.:-
SELECT * FROM tblSales WHERE CustomerNameID='Test Company' AND Year=2011
Using the same space-separating logic, this would produce components of:
[Code]...
View 2 Replies
Jan 23, 2010
i want to replace certain words each time they are detected in order to create a correct response. i have managed to replace the word"i" with "you" and "you" with "me" separatley but when both words are detected in the string it dont work....
ElseIf txtEnter.Text.Contains(" i ") Then
Dim ii As String
ii = Replace(txtEnter.Text, " i ", " you ")
[code]...
View 4 Replies
Oct 21, 2009
i have 2 groups of text in my text file
Bottom
11.0 28 Red (2 13.10 04.0) [1 16.71 33.3] 130611 2948 229111 28275
6.5 28 Blue (2 03.00 03.0) [1 05.36 58.3] 132111 -67725 191611 -51225
2.0 28 Blue (1 05.36 45.3) [1 05.36 58.3] 211111 51225 210454 34691
[Code].....
View 14 Replies
Aug 27, 2009
I'm reading a text file that has ZPL language for sending strings to a Zebra printer. Each line has one parameter that is replaced with a value. However, the line posted below has multiple parameters that need to be replaced with values.
'''''Line from text file
^FO005,005^A0R,035,025^FD(01)90723236{strLabelNumber}{intCheckDigit}(3201){strNetWeight}(11){strProductionDate}(21){strOrg}{strBoxNumber}^FS
[code]....
I can replace one parameter with one value using string.replace, but how would I continue to process the rest of the string? Would I replace the first parameter then reevaluate the string again to find another parameter until no more parameters are found?
View 6 Replies
Nov 14, 2011
I am trying to build an application which does the following :
1) write some text in a richtextbox
2) when user clicks a button, the app will replace the text with another text in {} braces.
what I want is that the next time, the regex searches for any text it should exclude those which are present in {}. for eg : my world is good world and a happy world and will be a better world for everyone. first pass - change word "world"
[Code]....
View 1 Replies
Jan 31, 2012
I have strings that look like this {/CSDC} CHOC SHELL DIP COLOR {17}
I need to extract the value in the first swirly brackets. In the above example it would be
/CSDC So far i have this code which is not working
[Code]...
View 3 Replies
Apr 25, 2012
Just have a list of words, such as:
gram (g)
kilogram (kg)
pound (lb)
just wondering how I would get the words within the brackets for example get the "g" in "gram (g)" and dim it as a new string. Possibly using regex?
View 3 Replies
Jul 14, 2009
I am trying to make a regex that will match strings between a comma only if the comma is outside of complete brackets. Brackets inside of " " should not count. Examples below. [code]
View 6 Replies
May 9, 2011
I have the following string [custID] = 'A99999999' I am trying the following to remove the square brackets and the single quotes Regex.Replace(sql, "/[[]']+/g", " ") but that's not working. I keep getting the same results Note: sql is a variable holding the string above. I want the result to be
View 5 Replies
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
Oct 15, 2011
I have a question regarding the dataset usage in Reporting Services. I have a stored procedure which returns multiple select statements (result tables), and I created a Dataset in Reporting Services 2005 with this stored procedure. The problem is that I can not reference the second or third result table, and I can only use the first select statement fields. Is this the limitation on Reporting Services Dataset or is there a way to use multiple table results in one dataset?
View 1 Replies
Apr 16, 2009
how would i get this USERNAME, USERID from this string:
Code:
<a href="javascript:attackWindow('USERNAME','USERID','50','RANDSTRING', 'RANDSTRING2')">
Adding the USERNAME to listbox, and then USERID into an array separated by a space.
View 2 Replies
Mar 30, 2011
How ever it is returning wrong results. Any one spot the mistake. Needs to return the username / ID from every online user from [code]...
View 3 Replies
Apr 17, 2009
i'm really new at the VB language only been doing for around 2 weeks.I hoping someone can help me with this, how would i get this USERNAME, USERID from a string
Adding the USERNAME to listbox, and then USERID into an array separated by a space. - I no how to do this part just the regex above remember i've only been doing for two weeks so i'm not very knowledged at this.
View 11 Replies
Nov 16, 2011
I have dates like the following (note trailing 'T')
2011-11-07T15:24:28
2011-11-07T
With regex i need to extract just the date part so both will look like this
20111107
20111107
.net Have a webservice that is returning a date like 2011-11-07T15:24:28, but on some occasions it returns date with no time but still with the trailing T. This causes .net's cdate function to bail out.
View 3 Replies
Jul 29, 2009
I have a sub that takes a string, replaces all characters that are not alphanumberic and or a "/" and replaces it with a space. Then it goes through and replaces all multiple spaces with a single space.
Right now I am using a string builder to do this. My problem is that this action must be done several hundred to thousand times depending on the filesize I am comparing it to (1 richtextbox line = 1 string)
I believe I should see a significant increase in performance if I can figure out how to do this using a single regex.replace function.How would I go about constructing a regex.replace function that would keep all alphanumberic characters and "/" and replace everything else with a single space?
[Code]...
View 6 Replies
Jan 2, 2010
I have 2 questions regarding replacing certain text in a string which has been found using regular expressions.For example this is my string:"<span style="font-weight: bold">This</span> is <span style="font-weight: bold">2010</span>"
View 4 Replies
Jun 21, 2011
Regex in VB2008.I have a file system directory that my code is watching. When a file is placed in that directory my code kicks off a processing application. Based on the filename structure, the code will perform different processes. So I need to match the filename structure specficially to get the correct processes to run on that file.My file name structure is: IK2YYYYMMDD_VV.e;where YYYYMMDD is well, the year, month and day. And VV is a verison number from 00-99 If the new file saved in the directory match this structure then I want a TRUE returned. From a filewatcher I get the filename as an "e.Name" (FileSystemEventArgs) variable. My current code to see if it matches the baseline structure is;
Dim IKPred2Match as New Regex ("^IK2.*\.e$") Dim ValidIKPred2Match as MatchCollection = IKPred2Match.Matches(e.Name)I've tried many different regex match patterns, and just can't seem to find the magic one.
View 2 Replies
Jul 1, 2011
I need an extremely simple regex pattern that matches anything within square brackets [].
Example:
This is a [test] text with [some] [examples].Required results: [test], [some], [examples].I don't want to get rid of the brackets, they should be included in the result (that should make it easier, right?)
If possible I'd like to exlude results that have whitespace in them, so things like [this string] should not be matched. If that gets too hard (probably not, but hey I can't even manage this :S) then I don't really mind, I can always check if the result contains whitespace myself.
I tried a lot of examples I could find online and ones that I could think of myself but none work. Note: I've been testing with the Visual Studio Find dialog (checking to use regular expressions obviously), maybe that's where the problem lies, because I don't really understand why some of these don't work...
Anyway, first thing I tried was simple: match the two brackets and one or more characters in between (that should be a +, right?)
View 4 Replies
Jan 27, 2009
I've got a string which could or could not contain the substring "/announce". I would like to replace this part of the string with "/scrape" if its found...so far nothing tricky. But heres the thing: I only want to replace it if the '/' in it is the last occurring in the string. Heres what I mean:
Heres a scenario where I want the replace to happen:
MyStringWithRandomText/announce?x=19
would become:
MyStringWithRandomText/scrape?x=19
And heres another scenario where the '/' in announce is not the last '/' occuring in the string, so I dont want to replace it:
MyStringWithRandomText/announce/foo?x=19
I hope that made sense. Not sure if there is a way to handle this by only using RegEx
View 2 Replies
Dec 23, 2011
I have file paths such as:
' Any number of folders before and after the Project name
C:acdProject1efgsomefile.someextension'
[code].....
View 1 Replies
Nov 8, 2011
How can I create a GUI in vb.net similar to the one above?i.e.there are "buttons" on the left which changes the main window when they are clicked.One way I thought of is create many panels overlapping and show/hide them when a certain button on the left is clicked.
View 2 Replies
May 29, 2009
I'm using VB.Net in an ASP.Net 2.0 app to run some regular expressions that remove some unnecessary markup. One of the things that I'd like to do is remove span elements that don't have any attributes in them:[code]I'd like to remove the outer span elements. Unfortunately, my regex above gives me this as a result, since the closing span matches the first one it comes across:[code]
View 4 Replies
Dec 3, 2010
I want to use Regex.Replace to replace a Match with a context sensitive value. I use the MatchEvaluator for this. But to make things simpler lets say I'm matching %v I want %v to be escapable, so if I use \%v it will not match. Anything else should match.
The pattern I came up with is this: (?:[^\]|^)%v It basically matches %v if it occurs at the beginning of the string, or if it follows any character except . It doesn't capture the first part of the expression.I know this isn't the "right" way to do it. But it worked just fine until I noticed that when I use this pattern in a replace, it includes the character before %v in the replacement(duh, right?)So, if I have ThisIsAValue:%v and I do Regex.Replace, replacing with the string Value, my result will be ThisIsAValueValue instead of ThisIsAValue:ValueI've tried googling this but the fact that "escape character" is so heavy in RegEx, all the results are geared towards the USAGE of escape characters instead of picking them out with a pattern.
View 1 Replies
Sep 5, 2009
I've been working with Regex and I've run into something that doesn't make sense to me; I either misunderstood how the Multiline option works, I'm not using it right, or it really just doesn't work like it's supposed to. This is a little test I made:
[Code]...
View 18 Replies
Mar 24, 2011
I'm in the middle of writing an application which fills two seperate listboxes with the name of all the contents in two different specified directories.The application is at the stage where this works, here is the code for it:
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
[code].....
View 3 Replies
Jan 30, 2012
I'm trying to write a virtual piano program. Each key plays a sound from the resources directory.How do i play two(or more) sounds at the same time if ex two keys are pressed. Or start playing another sound while one is still playing.
View 2 Replies