regex matching question

  • Thread starter Thread starter Saso Zagoranski
  • Start date Start date
S

Saso Zagoranski

Hi,

I'm creating a little knowledge base webservice, which would help my users
when they
encounter errors.

In my knowledge base I would have entries like this:
problem: Can't access file [*] because it is being used by another process
fix: the file is currently in use so you can't use it now.

Lets say an IOException is thrown in the application with the message:
"Can't access file 'myfile.txt' because it is being used by another process"

The error would then be sent to the webservice, the webservice would
try to match the error message with the kbase and send back the response
if one is found.

My guess is this would be best done with regular expressions, right?

Please help,
thanks,
saso
 
Saso Zagoranski said:
I'm creating a little knowledge base webservice, which would help my users
when they
encounter errors.

In my knowledge base I would have entries like this:
problem: Can't access file [*] because it is being used by another process
fix: the file is currently in use so you can't use it now.

Lets say an IOException is thrown in the application with the message:
"Can't access file 'myfile.txt' because it is being used by another process"

The error would then be sent to the webservice, the webservice would
try to match the error message with the kbase and send back the response
if one is found.

My guess is this would be best done with regular expressions, right?

Yes, that sounds like a good fit for regular expressions. One thing to
bear in mind, however, is that regular expressions can be difficult to
write. Will you be the person writing all the knowledge base entries,
and are you comfortable with regular expressions (or happy to learn
about them)?
 
Hi,

I will be the person who will write kbase entries and all of them
will be in the form:
text text [*] text text text
where [*] represents an any text. (I can use something else instead of [*]
if you
think it's better)

I don't have any knowledge of regex but I am willing to learn,
although I have to admit that I was hoping that there is an example out
there of how to do
what I'm looking for :)

thanks for your answer,
saso

Jon Skeet said:
Saso Zagoranski said:
I'm creating a little knowledge base webservice, which would help my
users
when they
encounter errors.

In my knowledge base I would have entries like this:
problem: Can't access file [*] because it is being used by another
process
fix: the file is currently in use so you can't use it now.

Lets say an IOException is thrown in the application with the message:
"Can't access file 'myfile.txt' because it is being used by another
process"

The error would then be sent to the webservice, the webservice would
try to match the error message with the kbase and send back the response
if one is found.

My guess is this would be best done with regular expressions, right?

Yes, that sounds like a good fit for regular expressions. One thing to
bear in mind, however, is that regular expressions can be difficult to
write. Will you be the person writing all the knowledge base entries,
and are you comfortable with regular expressions (or happy to learn
about them)?
 
Saso Zagoranski said:
I will be the person who will write kbase entries and all of them
will be in the form:
text text [*] text text text
where [*] represents an any text. (I can use something else instead of [*]
if you think it's better)

I don't have any knowledge of regex but I am willing to learn,
although I have to admit that I was hoping that there is an example out
there of how to do what I'm looking for :)

Well, to do that, you could just convert the text into a regular
expression by escaping the bits at the start and end (so it doesn't
matter if you've got something which is special to regular expressions)
and replace the [*] with something like .* (which matches any
characters, basically).

You *could* do all that by splitting the string into a start bit and an
end bit, then using string.StartsWith and string.EndsWith. However,
things would get hairy if you then found yourself with two [*] tokens.

I suggest you read the MSDN pages on regular expressions - they're
worth delving into.
 
Back
Top