RegExp to Remove Numbers in String Between Brackets

exceere

New Member
Joined
Jul 18, 2012
Messages
26
hello,

I tried to write a simple RegExp to remove Numbers in string between square brackets

Code:
Dim oRegExp As New RegExp, sName As String
    With oRegExp
        .Global = True
        sName = "Exeere 4242 [111AAAA222 222 BBB33333,33CCCC444-44DDDD5555]"
        .Pattern = "(\[)" & "(\D*)\d+(\D*)" & "(\])"
        sName = .Replace(sName, "$1$2$3$4" & "")
        Debug.Print sName
    End With

input string: Exeere 4242 [111AAAA222 222 BBB33333,33CCCC444-44DDDD5555]

Numbers in RED color should be removed.

Wanted Result = Exeere 4242 [AAAA BBB,CCCC-DDDD]

How can i do this?

Hint:

I wnat to remove any Numbers in the string between brackets regardless of the pattern of this string. (the pattern of the string between brackets may change)

I have posted this query in other forum and i get some solutions but am looking a silmpler code.

cross linked thread
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You had 2 suitable answers on the other forum ??
 
Upvote 0
Thank you Micheal M.

This is what i have mentioned in my thread.

BUT iam looking for simpler code.
 
Upvote 0
The obvious question is...why do you need / want simpler code, if provided code works ? 😎
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top