vb.net regex - getting string between two known words

Associate
Joined
18 Oct 2002
Posts
1,752
Location
Southern England
hi all,

banging my head against a wall with this so seeking some advice really.

I have a string which contains some data I need to grab as below:

"Published 20 DEC 1969

Last Update 21 DEC 1969"

I'm looking at grabbing the "20 DEC 1969" from the string using regex. I already have code that does this without regex but I'd like to try and do this with regex as a bit of an experiment.

Between "Published" and "20 DEC 1969" are a number of blank spaces. After "20 DEC 1969" is a line break before it then leads into "Last Update".

I have some regex which i've written to pull the "20 DEC 1969" but instead it pulls out nothing. I understand I may have to turn on Multiline support but not sure how to implement that.

The regex I have currently looks like this:

dim rx as new regex("\bPublished\b(.*?)\bLast Update\b")

Obviously I'm missing a trick here so could someone advise me here?

thanks
 
If you don't have Expresso installed already, get that running and you can play around with patterns to your hearts content. Great for learning regular expressions.

Code:
^Published\s+(.*)\r\n

That will put your date portion into the first numbered group.
 
Back
Top Bottom