RegExp Replace expression for paragraph numbering

Posted on 2008-10-17
Last Modified: 2012-05-05
I am using "Microsoft VBScript Regular Expressions 5.5"
I want to remove all paragraph numbering in a text document (string).
So what must the Replace Regular Expression be to replace all occurrences of "n.", "n.n", "nn.nn" and ".n" with a Null string?  (Where n is a digit from 0-9)
Question by:vergenoeg
  • 3
  • 3

Expert Comment

ID: 22738611

(with sed you need to add escapes sed 's/[0-9]\+\.[0-9]\+\|\.[0-9]\+\|[0-9]\+\.//g')
LVL 51

Expert Comment

ID: 22745655

Author Comment

ID: 22746958
I have a string "myString" which contains thousands of characters including paragraph numberings like "1.", "1.1", etc.
My code:
Public Sub ReplaceNow()
Dim objRegExp As RegExp
Set objRegExp = New RegExp
strReplace = ""
strPattern = "((?[0-9]+)?\.[0-9]+|[0-9]+\.)"
objRegExp.IgnoreCase = True
objRegExp.Global = True
strToReplace = GetText("c:\MyText.txt")
objRegExp.Pattern = strPattern
If (objRegExp.test(myString) = True) Then  ' <== fails here
    strResult = objRegExp.Replace(strToReplace, strReplace)
End If
Debug.Print (strResult)
End Sub

And then it fails on this statement:
If (objRegExp.test(myString) = True) Then
which means it could not find a match
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

LVL 51

Accepted Solution

ahoffmann earned 200 total points
ID: 22749748
oops, missed a colon, please try:


Also remember that I posted a raw regex (see the leading @) while you used it as string which behaves different. IIRC (M$'s stupid regex syntax) you have to properly escape metacharters in a string, in particular \ needs to be \\ then.

Author Closing Comment

ID: 31507065
Thanks very much, it works perfectly.

Author Comment

ID: 22751074
Thanks very much, it works perfectly.
LVL 51

Expert Comment

ID: 22752771
glad to have helped you (as I never touched any M$ tools:)
good luck

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question