Re: Need regular expression to parse string

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: moondaddy (moondaddy_at_nospam.com)
Date: 09/27/04


Date: Mon, 27 Sep 2004 11:27:21 -0500

Thanks for all the replies below. I ended up looping thru the data and
using the split function on the vbNewLine of the string. As you can see
below, the string has 4 or 5 vbNewLine(s). The string is parsed into an
array of 5 strings so I wrote some code to split the 2 parameters out of
each string by searching or spaces or vbTab, then trimming the data on each
side of the space or vbTab.

As for performance, its not an issue here since there might only be 20 line
items to parse out. But often I do data cleansing and one time I wrote
several regular expressions to help parse parameters out of 15000+ lines of
text and that took minutes to run, where as I wrote something similar in vba
years ago and took about 10 seconds to run through just as much data. So the
vba was more code to write and ran faster, but in the recent example, I
don't know if I could have written vb.net code to do the same kind of
sophisticated parsing regex did.

Thanks for the comments.

-- 
moondaddy@nospam.com
"Cor Ligthert" <notmyfirstname@planet.nl> wrote in message
news:eFjtAk6oEHA.2784@TK2MSFTNGP14.phx.gbl...
> Moondaddy,
>
> It is known by most regulars in this newsgroup that I do not like the
Regex.
> Think about it that is at least (for simple problems) about 20 times
slower
> than a normal loop and replace function.
>
> So I would use for your problem something as (not tested)
> \\\
> For each st as string in myrows
>    st = "param1=" & st
>    st = st.replace(" "," param2=")
> next
> ///
>
> I hope this helps?
>
> Cor
>
> "moondaddy"
>
> > I'm writing an app in vb.net 1.1 and I need to parse strings that look
> > similar to the one below.  All 5 rows will make up one string.  I have a
> > form where a use can copy/paste data like what you see below from excel,
> > word, notepad, etc.. into a textbox on my form.  I need to break each
line
> > into 2 numbers which I'll use as parameters for another function.  in
all
> > cases each line will be separated with a vbNewline and in most cases the
2
> > numbers in the line (2483 and 21 for example) will be separate be a tab
> > space, but I cant guarantee that.  It should however be some sort of
white
> > space in-between the 2 numbers.  I could split the string below into 5
> > smaller strings, but I'm short on a reliable way to consistently parse
the
> > 2
> > numbers from each string.
> >
> > 2483    21
> > 2484    23
> > 24853    3
> > 2486    14
> > 2487     5
> >
> > the end result of what I want to do is parse this string where I can
feed
> > each value into parameters like this
> >
> > param1=2483    param2=21
> > param1=2484    param2=23
> > param1=24853    param2=3
> > param1=2486    param2=14
> > param1=2487     param2=5
> >
> >
> > any good recommendations?
> >
> > Thanks
> >
> > -- 
> > moondaddy@nospam.com
> >
> >
>
>


Relevant Pages

  • Re: Help With PyParsing of output from win32pdhutil.ShowAllProcesses()
    ... None to a string). ... Still have an urge to parse with pyparsing? ... pyparsing Dict class. ... keys from the parsed data, so it looks like you are already thinking ...
    (comp.lang.python)
  • RE: Need regular expression to parse string
    ... Why not just use the Split function? ... lines using vbNewLine as the delimiter, then process each line in a For Next ... All 5 rows will make up one string. ... but I'm short on a reliable way to consistently parse the 2 ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Pyparsing help
    ... our grammar isn't parsing the METAL2 entry at all. ... input string". ... successful parse, then restored half of the entries I removed, until I ... Layer PRBOUNDARY ...
    (comp.lang.python)
  • Re: Nasty code...but please critique it anyway :-)
    ... You only need <string>, move all the other #includes to the C++ files. ... compilation times. ... You may want to use a std::stringstream to parse the integer, ... You may want to flush the output stream after printing menutext, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Nasty code...but please critique it anyway :-)
    ... You only need <string>, move all the other #includes to the C++ files. ... compilation times. ... You may want to use a std::stringstream to parse the integer, ... You may want to flush the output stream after printing menutext, ...
    (comp.lang.cpp)