Regular Expressions

  • Thread starter Thread starter rdi
  • Start date Start date
R

rdi

I get the idea of how to create the search patterns. But what I'm having
trouble with is how to actually implement regular expressions. I can't seem
to find any code that actually USES them. In all the posts I've found on
google all anyone talked about was creating the actual search pattern.

Could someone show me an actual sub that will use RegEx to check if the word
"Test" is in each of the strings in the array tstArray. I'm just looking
for a simple example SUB.

TIA

dim tstArray(5)
tstArray(0) = "-----Test-----"
tstArray(1) = "kkkkTest----"
tstArray(2) = "kkkkkkkkkkk"
tstArray(3) = "Test------"
tstArray(4) = "kkadTest--"
tstArray(5) = "adasjdfkasdf"

Pattern = "Test"
 
RDI,
Using a RegEx to find a fixed word such as Test is a very inefficient use of
a RegEx. Also RegEx will not help searching an array per se. (you would need
to apply the RegEx to each element of the array manually).

Generally you would use a RegEx when you want to find a pattern inside of a
single String (this single string could be a 1M text file). For example, you
want to find all the hyperlinks in an HTML (like) document. Or you want to
verify that a string (from a text box for example) is a valid email address,
or you want to verify that an input string matches the Policy Number format
(XXNNNN).

The following link provide 5 good sample Regular Expressions, along with
using them:

http://msdn.microsoft.com/library/d...guide/html/cpconregularexpressionexamples.asp


The following site is a good tutorial & reference on regular expressions.

http://www.regular-expressions.info/

Hope this helps
Jay
 
rdi

the simplest way to find the word "Test" in your test array i

public sub test_array(ByVal tstArray() as String, ByRef found() as Boolean, ByVal arrayBound as integer

Dim m as Matc
Dim index as Intege

for index = 0 to arrayBoun
m = regex.match(tstArray(index), "Test"
if m.success the
found(index) = tru
els
found(index) = fals
nex
end su

If you want to put the pattern in the parameter list instead of using the literal, just add ByVal pattern as string and call it that way

Everything you ever wanted to know about Regexes in .NET is in "Mastering Regular Expressions" by Jeffrey E.F. Friedl. It's an O'Reilly book. I got mine at Barnes and Noble for about $40.00. Chapter 9 is all about how .NET implements regexes.

Let me know by e-mail if you need more info
JimT
 
Jay,

I understand that it's "very inefficient use". I was just looking for
a simple example and thought that by offering what I did, it would
keep things simple.

My ultimate goal is to use REGEX to parse an email message. I have a
class that downloads email from my POP3 server and I have the
message--but it includes all the headers and EVERYTHING. I need to
parse out the subject, To, & from fields as well as just the body of
the message--leaving behind the extraneous stuff.

Thanks for the links though. I'll look them over.
 
Back
Top