Wrox Programmer Forums
BOOK: Beginning Regular Expressions
This is the forum to discuss the Wrox book Beginning Regular Expressions by Andrew Watt; ISBN: 9780764574894
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Regular Expressions section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 26th, 2006, 04:02 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default Extracting Text


I am totally incompetent when comes to regular expressions, so I come asking for help. I'm sure this is easy, but I have no idea how to do this.

I need some help constructing an expression to parse out some particular text from a text file.

I know I could do this the "hard way" by scanning the input strings looking for the particular characters I'm interested in, but there is enough potential variations in the text that I think a regular expression is the best solution to my problem.

The code is VB.NET and I need to see if the scanned text contains a certain set of characters, and if so, extract off some following characters.

The text will look something like:

CASE NUMBER: 123456789

There may be leading or trailing whitespace in this line. There may be any number of intervening spaces, but there will always be at least 1, between the NUMBER: text literal and the digits which follow. There may or may not be a colon after NUMBER. The number of digits may vary; there are always at least 5, and there may be as many as 12 digits.

I need to extract those digits into a named group, at least I think I need to - I need the case number for subsequent processing, and a named group seems the best way to handle that, but what do I know? Once I find the case number in the text, I'm done - there is no more need to parse anything else.

That's it. Simple really, but I've wasted a lot of time fumbling around so I thought I'd ask for some help,


Jeff Mason
Custom Apps, Inc.
-- Jeff
Old October 24th, 2006, 06:38 AM
Registered User
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

I think this is the regexp you are looking for:

CASE NUMBER:\s+(\d+)\s*

But if you are not seeking your string in a whole text, you should use:

^CASE NUMBER:\s+(\d+)\s*$

Similar Threads
Thread Thread Starter Forum Replies Last Post
extracting multi-line text. Ceromus C# 0 November 7th, 2008 10:06 PM
Extracting a flexibel amount of text part 2 jmaronilla PHP Databases 0 July 28th, 2008 08:22 PM
Extracting a flexible amount of text from a field scottiegirl PHP Databases 2 July 28th, 2008 09:57 AM
Help extracting text from a regular expression crazymanju BOOK: Beginning Regular Expressions 0 April 10th, 2007 05:43 AM
Extracting text between tags aware Classic ASP Professional 4 December 24th, 2003 04:25 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.