D
Dave
I was wondering if someone could help me with a regular expression problem.
I have a string of characters and numbers that will contain some information
about chemical formulas. I need to parse out of the string what elements it
contains and which numbers are associated with those elements. The problem
I'm having is that some elements contain 2 characters and some just one. For
example, the elements Br and B. I had originally set up a search pattern for
the Regex object to have a complete list of the periodic table "[B|Br|
etc.]" and was going to use matches method to get a collection of all
elements matched in the string.
dim myRegex as regularexpressions.regex("[B|Br| the rest of periodic table
here ]", regexoptions.ignorecase)
dim matchesMade as regularexpressions.matchescollection
matchesMade = myregex.Matches(aString)
for each matchMade as regularexpressions.match in matchesMade
' do stuff to the match here
next
The problem is the logic above would get a match on B even if the formula
really contain Br and I need to distinguish between the two.
Any suggestions on how I do this would be appreciated.
Thanks,
Dave
I have a string of characters and numbers that will contain some information
about chemical formulas. I need to parse out of the string what elements it
contains and which numbers are associated with those elements. The problem
I'm having is that some elements contain 2 characters and some just one. For
example, the elements Br and B. I had originally set up a search pattern for
the Regex object to have a complete list of the periodic table "[B|Br|
etc.]" and was going to use matches method to get a collection of all
elements matched in the string.
dim myRegex as regularexpressions.regex("[B|Br| the rest of periodic table
here ]", regexoptions.ignorecase)
dim matchesMade as regularexpressions.matchescollection
matchesMade = myregex.Matches(aString)
for each matchMade as regularexpressions.match in matchesMade
' do stuff to the match here
next
The problem is the logic above would get a match on B even if the formula
really contain Br and I need to distinguish between the two.
Any suggestions on how I do this would be appreciated.
Thanks,
Dave