tags:

views:

126

answers:

2

i would like to use the following regex in VB.net:

(\d+.\d+)|(\?\?\?\?\?\?)

how would i do it? i actually need to edit a string to put it in the specified format

+4  A: 
Dim isMatch As Boolean = _
  System.Text.RegularExpressions.RegEx.IsMatch("My test string", _
     "((\d+.\d+)|(\?\?\?\?\?\?))")

Note the extra parenthesis I added... I'm pretty sure they are needed, so both sides of the "or" ("|") are considered part of the same group.

It also looks like there may be an error in your expression in "\d+.\d+". If the "." you have there is intended to match a literal period, you should use "\." instead. Otherwise, the "." in RegEx lingo is a single-character wildcard.

(I'm assuming you're looking for a literal dot below...)

You could shorten your expression to this:

"((\d+\.\d+)|?{6})"

Question marks don't mean anything in RegEx in the spot they appear in the expression, so they don't have to be escaped with a backslash. The curly braces show the number of repetitions you want to find of the thing before it (the question mark).

richardtallent
how would i get the output of this regex?
I__
would i have to import anything?
I__
@alex- System.Text.RegularExpressions is the import that he included in code
TStamper
There is no "output" to this regular expression. The code I provided will tell you whether a particular input string matches or does not match the expression.If you want to do a replacement of one thing with another, or capture matches of this expression in a longer string, you'll need to be more clear in your question.
richardtallent
hey richard i have a string and i need to put it in the specified format
I__
@alex, regex isn't used to format strings, it is used to see if strings match a pattern, and if so, to potentially do a fancy search and replace on them.Please start a new question and specify that you're looking to format a number into the form provided. You'll need to specify when you want a decimal number back, and when you want question marks.
richardtallent
@alex, as a hint, I think you're looking for the String.Format function.http://msdn.microsoft.com/en-us/library/system.string.format.aspx
richardtallent
+2  A: 
Dim MyRegex As Regex = New Regex("(\d+.\d+)|(\?\?\?\?\?\?)") //construct a Regex object  that you can call later
TStamper
For reference http://www.regular-expressions.info/dotnet.html: refer to System.Text.RegularExpressions Overview (Using VB.NET Syntax)
TStamper
yes and how would i use this on a string?
I__
the link gives many examples
TStamper