Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression Pattern

Status
Not open for further replies.

Custom24

Programmer
Nov 27, 2001
591
GB
Hi
Would anyone know what the pattern is to return all bracketed text from a string
For example
"I (me) feel (think) that sometimes (that is most (high percentage) of the time) I don't like Regular Expressions"

should return the three matches (me), (think), (that is most (high percentage)

with the pattern "\(.*\)", but it only returns

(me) feel (think) that sometimes (that is most (high percentage) of the time)

I can see why it is doing this, but how do I get it to use the brackets properly?
 
I have worked it out a bit

"\([^\)]*\)"

but it does not account for repeated brackets

eg Hello (Goodbye(Farewell)) Hello

Any ideas?
 
I have not been able to get the (that is most (high percentage) of the time) to pop out. But otherwise, here is what I have been able to come up with.

k = "I (me) feel (think) (that sometimes) (that is most (high percentage) of the time) I don't like Regular Expressions"

' regExpTest "\(", k
' regExpTest "\(\w+\)", k
' regExpTest "\(high percentage\)", k
' regExpTest "\([a-zA-Z\s]+\)", k
regExpTest "\([a-zA-Z\s\(]+\)", k

Sub RegExpTest(strMatchPattern,strPhrase)

Set regEx = New RegExp
regEx.Global = true
regEx.Pattern = strMatchPattern
Set Matches = regEx.Execute(strPhrase)

For each match in Matches
strReturnStr = "Match found at position "
strReturnStr = strReturnStr & match.FirstIndex & ". Match value is "'
strReturnStr = strReturnStr & match.value & "'."
msgbox strReturnstr
Next

msgbox "Done"

End sub

If you get it to work, please post as I would like to see.

Thanks,

Parke
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top