Split string by regular expression (ie. date) 
Author Message
 Split string by regular expression (ie. date)

I have a string that looks something like this:-

strNotes "07/06/2002 12:23:37 - COAT selected07/06/2002 12:23:38 - Staff
verified by Phil Dempsey07/06/2002 12:23:39 - Client verified by Phil
Dempsey18/06/2002 16:16:04 - Cancelled set by Phil Dempsey: Reason - entered
in error18/06/2002 16:16:07 - Client verified by Phil Dempsey"

Can anyone tell me if its possbile to split the string by using a regular
expression like
[0-9][0-9]/[0-9][0-9]/[0-9][0-9]

ie. I want to split the string by the dates so that i get the following:-

    arrNotes = split(strNotes, ([0-9][0-9]/[0-9][0-9]/[0-9][0-9]))

    arrNotes(0) = "07/06/2002 12:23:37 - COAT selected"
    arrNotes(1) = "07/06/2002 12:23:38 - Staff verified by Phil Dempsey"
    arrNotes(2) = "07/06/2002 12:23:39 - Client verified by Phil Dempsey"
    arrNotes(3) = "18/06/2002 16:16:04 - Cancelled set by Phil Dempsey:
Reason - entered in error"
    arrNotes(4) = "18/06/2002 16:16:07 - Client verified by Phil Dempsey"

Many thanks for any suggestions

Dan Williams



Mon, 25 Jul 2005 23:50:53 GMT  
 Split string by regular expression (ie. date)

Quote:

> I have a string that looks something like this:-

> strNotes "07/06/2002 12:23:37 - COAT selected07/06/2002 12:23:38 - Staff
> verified by Phil Dempsey07/06/2002 12:23:39 - Client verified by Phil
> Dempsey18/06/2002 16:16:04 - Cancelled set by Phil Dempsey: Reason - entered
> in error18/06/2002 16:16:07 - Client verified by Phil Dempsey"

> Can anyone tell me if its possbile to split the string by using a regular
> expression like
> [0-9][0-9]/[0-9][0-9]/[0-9][0-9]

> ie. I want to split the string by the dates so that i get the following:-

>     arrNotes = split(strNotes, ([0-9][0-9]/[0-9][0-9]/[0-9][0-9]))

>     arrNotes(0) = "07/06/2002 12:23:37 - COAT selected"
>     arrNotes(1) = "07/06/2002 12:23:38 - Staff verified by Phil Dempsey"
>     arrNotes(2) = "07/06/2002 12:23:39 - Client verified by Phil Dempsey"
>     arrNotes(3) = "18/06/2002 16:16:04 - Cancelled set by Phil Dempsey:
> Reason - entered in error"
>     arrNotes(4) = "18/06/2002 16:16:07 - Client verified by Phil Dempsey"

If you can live with a Matches collection instead of an array:

strNotes = "07/06/2002 12:23:37 - COAT selected07/06/2002 12:23:38 - Staff " _
         & "verified by Phil Dempsey07/06/2002 12:23:39 - Client verified " _
         & "by Phil Dempsey18/06/2002 16:16:04 - Cancelled set by Phil " _
         & "Dempsey: Reason - entered in error18/06/2002 16:16:07 - Client "_
         & "verified by Phil Dempsey"

With New RegExp
  .Pattern = "\d\d/\d\d/\d{4}.*?(?=\d\d/\d\d/\d{4}|$)"
  .Global = True
  Set colNotes = .Execute(strNotes)
End With

For I=0 To colNotes.Count-1
  WScript.Echo colNotes(I)
Next

--
Steve

There is a foolish corner in the brain of the wisest man. -Aristotle



Tue, 26 Jul 2005 01:48:19 GMT  
 Split string by regular expression (ie. date)
Cheers for that.

I sort of found a way to do it and its very similar to yours.
Instead on echoing the colNotes though i just assigned it to an array.

Jobs a gooden.

Dan


Quote:

> > I have a string that looks something like this:-

> > strNotes "07/06/2002 12:23:37 - COAT selected07/06/2002 12:23:38 - Staff
> > verified by Phil Dempsey07/06/2002 12:23:39 - Client verified by Phil
> > Dempsey18/06/2002 16:16:04 - Cancelled set by Phil Dempsey: Reason -
entered
> > in error18/06/2002 16:16:07 - Client verified by Phil Dempsey"

> > Can anyone tell me if its possbile to split the string by using a
regular
> > expression like
> > [0-9][0-9]/[0-9][0-9]/[0-9][0-9]

> > ie. I want to split the string by the dates so that i get the
following:-

> >     arrNotes = split(strNotes, ([0-9][0-9]/[0-9][0-9]/[0-9][0-9]))

> >     arrNotes(0) = "07/06/2002 12:23:37 - COAT selected"
> >     arrNotes(1) = "07/06/2002 12:23:38 - Staff verified by Phil Dempsey"
> >     arrNotes(2) = "07/06/2002 12:23:39 - Client verified by Phil
Dempsey"
> >     arrNotes(3) = "18/06/2002 16:16:04 - Cancelled set by Phil Dempsey:
> > Reason - entered in error"
> >     arrNotes(4) = "18/06/2002 16:16:07 - Client verified by Phil
Dempsey"

> If you can live with a Matches collection instead of an array:

> strNotes = "07/06/2002 12:23:37 - COAT selected07/06/2002 12:23:38 - Staff
" _
>          & "verified by Phil Dempsey07/06/2002 12:23:39 - Client verified
" _
>          & "by Phil Dempsey18/06/2002 16:16:04 - Cancelled set by Phil " _
>          & "Dempsey: Reason - entered in error18/06/2002 16:16:07 - Client
"_
>          & "verified by Phil Dempsey"

> With New RegExp
>   .Pattern = "\d\d/\d\d/\d{4}.*?(?=\d\d/\d\d/\d{4}|$)"
>   .Global = True
>   Set colNotes = .Execute(strNotes)
> End With

> For I=0 To colNotes.Count-1
>   WScript.Echo colNotes(I)
> Next

> --
> Steve

> There is a foolish corner in the brain of the wisest man. -Aristotle



Tue, 26 Jul 2005 18:05:22 GMT  
 Split string by regular expression (ie. date)

I've just tried your suggestion, and i get the following error

Error Type:
Microsoft VBScript runtime (0x800A139A)
Unexpected quantifier
/bookings/shiftinfo2.asp, line 65

Any ideas?

Dan

Quote:


> > I have a string that looks something like this:-

> > strNotes "07/06/2002 12:23:37 - COAT selected07/06/2002 12:23:38 - Staff
> > verified by Phil Dempsey07/06/2002 12:23:39 - Client verified by Phil
> > Dempsey18/06/2002 16:16:04 - Cancelled set by Phil Dempsey: Reason - entered
> > in error18/06/2002 16:16:07 - Client verified by Phil Dempsey"

> > Can anyone tell me if its possbile to split the string by using a regular
> > expression like
> > [0-9][0-9]/[0-9][0-9]/[0-9][0-9]

> > ie. I want to split the string by the dates so that i get the following:-

> >     arrNotes = split(strNotes, ([0-9][0-9]/[0-9][0-9]/[0-9][0-9]))

> >     arrNotes(0) = "07/06/2002 12:23:37 - COAT selected"
> >     arrNotes(1) = "07/06/2002 12:23:38 - Staff verified by Phil Dempsey"
> >     arrNotes(2) = "07/06/2002 12:23:39 - Client verified by Phil Dempsey"
> >     arrNotes(3) = "18/06/2002 16:16:04 - Cancelled set by Phil Dempsey:
> > Reason - entered in error"
> >     arrNotes(4) = "18/06/2002 16:16:07 - Client verified by Phil Dempsey"

> If you can live with a Matches collection instead of an array:

> strNotes = "07/06/2002 12:23:37 - COAT selected07/06/2002 12:23:38 - Staff " _
>          & "verified by Phil Dempsey07/06/2002 12:23:39 - Client verified " _
>          & "by Phil Dempsey18/06/2002 16:16:04 - Cancelled set by Phil " _
>          & "Dempsey: Reason - entered in error18/06/2002 16:16:07 - Client "_
>          & "verified by Phil Dempsey"

> With New RegExp
>   .Pattern = "\d\d/\d\d/\d{4}.*?(?=\d\d/\d\d/\d{4}|$)"
>   .Global = True
>   Set colNotes = .Execute(strNotes)
> End With

> For I=0 To colNotes.Count-1
>   WScript.Echo colNotes(I)
> Next

> --
> Steve

> There is a foolish corner in the brain of the wisest man. -Aristotle



Tue, 26 Jul 2005 20:50:25 GMT  
 Split string by regular expression (ie. date)

Quote:

> I've just tried your suggestion, and i get the following error

> Error Type:
> Microsoft VBScript runtime (0x800A139A)
> Unexpected quantifier
> /bookings/shiftinfo2.asp, line 65

> Any ideas?

You have to update your script engine to at least VBScript 5.5. That's when lazy
match patterns (e.g. ".*?") were introduced.

You can download Windows Script 5.6 from this page (it has a link to download
older versions):
http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...

--
Steve

What a heavy oar the pen is, and what a strong current ideas are to row in!
-Gustave Flaubert



Tue, 26 Jul 2005 23:16:50 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Split string by regular expression (ie. date)

2. Split / Regular Expressions help in VB.NET

3. Split with regular expression

4. Date data validation using regular expression

5. Need Regular Expression to strip non-numeric characters from string

6. filtering a string with regular expressions

7. regular expressions with string.replace

8. regular expression to remove html tags from string

9. processing a string with regular expressions

10. Matching Mutliple Strings with Regular Expressions

11. string manipulation, regular expressions

12. Do regular expressions work in IE?

 

 
Powered by phpBB® Forum Software