By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

regex

P: n/a
jg
I made a mistake somewhere in my vb code and I look, check and read against
the articles and help on regex, I still can't find the mistake I made.

I know my test string and the test patterns works, because I used on a vs.
script to check. I also believe I foolwed followed the regex syntax for
dotnet.

here is the source code for the function and testing

Public Function regtest(ByVal StringIn As String, ByVal patrn As
String) As Integer
' Create a new Regex object.
Dim r As New Regex(patrn)
' Find a single match in the input string.
Dim m As Match = r.Match(StringIn)
If m.Success Then
' Print out the character position where a match was found.
' (Character position 3 in this case.)
' Console.WriteLine("Found match at position " &
m.Index.ToString())
regtest = m.Index
else
Return -1
End If
End Function
The values for StringIn is "Mon, 2005-Feb-13 and some stuff"

for patrn is

"(\b([1-3][0-37-9]){0,1}[0-9][0-9][ -](([JFMASOND][AEPUCO][NBRYNLGPTVC]([A-Z]{0,6}))|([01]{0,1}[0-9]))[
-][01]{0,1}[0-9])"

The function regtest should return a number of 5 , at least not minus 1
which is what I got

Your help spotting the error is greatly appreciated.

Thank you for your time.


Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi jg,

My 'only' comment would be whether you have commented out the line
'm.Index.ToString' and this is part of the commented previous line!

Otherwise, your code looks good and should return your string.......assuming
it is actually found. Just note that I don't know whether the match method
is case sensitive. Not sure if this helps.

Good luck, Phil

"jg" <ju**@mail.pls> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
I made a mistake somewhere in my vb code and I look, check and read against
the articles and help on regex, I still can't find the mistake I made.

I know my test string and the test patterns works, because I used on a vs.
script to check. I also believe I foolwed followed the regex syntax for
dotnet.

here is the source code for the function and testing

Public Function regtest(ByVal StringIn As String, ByVal patrn As
String) As Integer
' Create a new Regex object.
Dim r As New Regex(patrn)
' Find a single match in the input string.
Dim m As Match = r.Match(StringIn)
If m.Success Then
' Print out the character position where a match was found.
' (Character position 3 in this case.)
' Console.WriteLine("Found match at position " &
m.Index.ToString())
regtest = m.Index
else
Return -1
End If
End Function
The values for StringIn is "Mon, 2005-Feb-13 and some stuff"

for patrn is

"(\b([1-3][0-37-9]){0,1}[0-9][0-9][ -](([JFMASOND][AEPUCO][NBRYNLGPTVC]([A-Z]{0,6}))|([01]{0,1}[0-9]))[
-][01]{0,1}[0-9])"

The function regtest should return a number of 5 , at least not minus 1
which is what I got

Your help spotting the error is greatly appreciated.

Thank you for your time.


Nov 21 '05 #2

P: n/a
jg
case sensitivity was part of the problem which I fixed with
RegexOptions.IgnoreCase
However there is still problem with my regex pattern,
I could test with simple one like "FEB", or
"((JAN)|(FEB)|(MAR)|(APR)|(MAY)|(JUN)|(JUL)|(AUG)| (SEP)|(OCT)|(NOV)|(DEC))"
and get the right answer but not
'([ADFJMNOS][ACEOPU][BCGLNPRTVY])"
In other word I got syntax problem with the month pattern

"Phil" <Ph**@nospam.com> wrote in message
news:dd**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Hi jg,

My 'only' comment would be whether you have commented out the line
'm.Index.ToString' and this is part of the commented previous line!

Otherwise, your code looks good and should return your
string.......assuming it is actually found. Just note that I don't know
whether the match method is case sensitive. Not sure if this helps.

Good luck, Phil

"jg" <ju**@mail.pls> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
I made a mistake somewhere in my vb code and I look, check and read
against the articles and help on regex, I still can't find the mistake I
made.

I know my test string and the test patterns works, because I used on a
vs. script to check. I also believe I foolwed followed the regex syntax
for dotnet.

here is the source code for the function and testing

Public Function regtest(ByVal StringIn As String, ByVal patrn As
String) As Integer
' Create a new Regex object.
Dim r As New Regex(patrn)
' Find a single match in the input string.
Dim m As Match = r.Match(StringIn)
If m.Success Then
' Print out the character position where a match was found.
' (Character position 3 in this case.)
' Console.WriteLine("Found match at position " &
m.Index.ToString())
regtest = m.Index
else
Return -1
End If
End Function
The values for StringIn is "Mon, 2005-Feb-13 and some stuff"

for patrn is

"(\b([1-3][0-37-9]){0,1}[0-9][0-9][ -](([JFMASOND][AEPUCO][NBRYNLGPTVC]([A-Z]{0,6}))|([01]{0,1}[0-9]))[
-][01]{0,1}[0-9])"

The function regtest should return a number of 5 , at least not minus 1
which is what I got

Your help spotting the error is greatly appreciated.

Thank you for your time.



Nov 21 '05 #3

P: n/a
One last 'suggestion' from me then, try this:-

Public Function regtest(ByVal StringIn As String, ByVal patrn As
String) As Integer
' Create a new Regex object.
Dim newPtrn as string = Trim(patrn)
Dim r As New Regex(newPtrn)

Good luck. Phil

"jg" <ju**@mail.pls> wrote in message
news:e6*************@TK2MSFTNGP09.phx.gbl...
case sensitivity was part of the problem which I fixed with
RegexOptions.IgnoreCase
However there is still problem with my regex pattern,
I could test with simple one like "FEB", or

"((JAN)|(FEB)|(MAR)|(APR)|(MAY)|(JUN)|(JUL)|(AUG)| (SEP)|(OCT)|(NOV)|(DEC))"
and get the right answer but not
'([ADFJMNOS][ACEOPU][BCGLNPRTVY])"
In other word I got syntax problem with the month pattern

"Phil" <Ph**@nospam.com> wrote in message
news:dd**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Hi jg,

My 'only' comment would be whether you have commented out the line
'm.Index.ToString' and this is part of the commented previous line!

Otherwise, your code looks good and should return your
string.......assuming it is actually found. Just note that I don't know
whether the match method is case sensitive. Not sure if this helps.

Good luck, Phil

"jg" <ju**@mail.pls> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
I made a mistake somewhere in my vb code and I look, check and read
against the articles and help on regex, I still can't find the mistake I
made.

I know my test string and the test patterns works, because I used on a
vs. script to check. I also believe I foolwed followed the regex syntax
for dotnet.

here is the source code for the function and testing

Public Function regtest(ByVal StringIn As String, ByVal patrn As
String) As Integer
' Create a new Regex object.
Dim r As New Regex(patrn)
' Find a single match in the input string.
Dim m As Match = r.Match(StringIn)
If m.Success Then
' Print out the character position where a match was found.
' (Character position 3 in this case.)
' Console.WriteLine("Found match at position " &
m.Index.ToString())
regtest = m.Index
else
Return -1
End If
End Function
The values for StringIn is "Mon, 2005-Feb-13 and some stuff"

for patrn is

"(\b([1-3][0-37-9]){0,1}[0-9][0-9][ -](([JFMASOND][AEPUCO][NBRYNLGPTVC]([A-Z]{0,6}))|([01]{0,1}[0-9]))[
-][01]{0,1}[0-9])"

The function regtest should return a number of 5 , at least not minus 1
which is what I got

Your help spotting the error is greatly appreciated.

Thank you for your time.




Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.