Link to home
Start Free TrialLog in
Avatar of vergenoeg
vergenoeg

asked on

RegExp Replace expression for paragraph numbering

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)
Avatar of zmo
zmo

's/[0-9]+\.[0-9]+|\.[0-9]+|[0-9]+\.//g'

(with sed you need to add escapes sed 's/[0-9]\+\.[0-9]\+\|\.[0-9]\+\|[0-9]\+\.//g')
@"((?[0-9]+)?\.[0-9]+|[0-9]+\.)"
Avatar of vergenoeg

ASKER

ahoffmann,
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
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much, it works perfectly.
Thanks very much, it works perfectly.
glad to have helped you (as I never touched any M$ tools:)
good luck