0

I'm trying to create a regex that will matches with

"8-9."

but won't matches with

"8-9........"

I tried lots of possibilities yet, but still can't find the right one.

3
  • 3
    Please show what you have tried and how it fails. Commented Sep 13, 2011 at 13:55
  • To be clear: you want to match exactly the characters "8-9." (eight dash nine dot) and that's not a regex pattern, yes? Or do you want to match all digits between 8 and 9 followed by any character? Commented Sep 13, 2011 at 13:57
  • What is the string you want to match? What do you not want to match? how does the pattern look that you have tried? ... You need to be a lot more specific. Commented Sep 13, 2011 at 13:57

2 Answers 2

2

Without a better worded question, ^8-9$ should do it..

Sign up to request clarification or add additional context in comments.

Comments

1

try

Dim r As Regex = New Regex("8\-9")
'Look for match
Dim m As Match = r.Match(mystring)

also might use

Dim r As Regex = New Regex("^8\-9$")

if you want a single word

4 Comments

- has no special meaning unless it's used inside a character class (e.g. [a-z]).
In VB, x As Y = new Y… should always be replaced by x As New Y….
@Konrad, is that VB's equivalent of var? I've always wondered.
@Blindy No. VB’s equivalent of var is Dim without a data type, when Option Infer is enabled. So just Dim x = "Hello". However, due to the above-mentioned syntax shortcut, this is less often necessary than var in C#.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.