Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

Regular Expression Issue/Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stephen Costanzo - 09 Aug 2005 19:00 GMT
I have inherited an application that uses Regular Expressions to find items
out of a data string and I am getting an odd result. It appears the regular
expression engine is grabbing the wrong value. For ease of the post I have
simply grabbed the relevant pieces of code without comments.

Dim Data As String = "fileCountThreshold=10, fileSizeThreshold=512,
foldername=C:\logs\, " & _
"fileSizeUnit=kilobytes, fileAgeThreshold=1, fileAgeUnit=months,
addMethod=true, " & _
"addPidTid=false, fileNameTemplate='console-{1:MMM-yy}-{0:0000}.log'"

Dim defaultValue As Boolean = False

Dim m As Match = Regex.Match(Data, "(?<=addPidTid=)false|true",
RegexOptions.IgnoreCase)

If m.Success Then
Debug.WriteLine(Boolean.Parse(m.Value))
Else
Debug.WriteLine(defaultValue)
End If

The m value returns the fact that it was successful in finding the value and
it indicates that the value found is true. However the value is true for the
addMethod part of the data. Other values include:
m.Index = 141 (which points to the first true in the line)
m.Length = 4
m.Captures.Count=1

If I put this into the code (following the first check)
 Dim m1 As Match = Regex.Match(Data,
"(?<=fileAgeThreshold=('|"")*)[^'"",]+", RegexOptions.IgnoreCase)
 If m1.Success Then
  Debug.WriteLine(m1.Value)
 Else
  '-- check for the ='' ="" =, case (empty string)
  If Regex.IsMatch(Data, Name & "=['"",]['""]*", RegexOptions.IgnoreCase)
Then
   Debug.WriteLine("")
  Else
   Debug.WriteLine(sdefault)
  End If
 End If

It correctly finds the value 1.

Any help would be appreciated.
Oliver Sturm - 10 Aug 2005 11:14 GMT
> Dim m As Match = Regex.Match(Data, "(?<=addPidTid=)false|true",
> RegexOptions.IgnoreCase)

The problem is that the | operator binds too strongly. You need to use
another pair of parens to make it work:

  (?<=addPidTid=)(false|true)

               Oliver Sturm
Signature

omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.