Locating square brackets in wildcard Find

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15587
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Locating square brackets in wildcard Find

Post by ChrisGreaves »

I am starting to use Wildcard search after reading Mike's post to locate foreign characters.
The attached document (with a VBA module) contains text, and the VBA code is my first attempt at detecting different "sub-sentences", phrases within a sentence which (phrases) can be parsed as a form of sentence.
My smart-quotes string found “rules”, which pleased me.
My parentheses string found (and estimating evidence). which pleased me even more
but
my string for square-brackets fails to locate [Footnote]
and I suspect that I need some escape character to tell the Find object that within the square brackets I am saying that I want to find square brackets.

Code: Select all

[“][0-9A-z ]{1,}[”]
[(][0-9A-z ]{1,}[)]
[[][0-9A-z ]{1,}[]]
My debug window shows me this, and I know that the third search string is not working.

As well I fail to locate (Book iv., ch. ii., § 4.) because right now I am specifying alpha, digit, and space within my search string, but not comma, period, or silcrow
Please and thank you, how do I specify (for the second search string) "every character except the left- and right-parenthesis"?

Thanks
Chris
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Locating square brackets in wildcard Find

Post by HansV »

Why not use

Code: Select all

Function FindNestedStatement(sel As Selection, strEmbrace As String)
    Dim strFindText As String
    With sel.Find
        .ClearFormatting
        strFindText = "\" & Left(strEmbrace, 1)
        strFindText = strFindText & "*"
        strFindText = strFindText & "\" & Right(strEmbrace, 1)
        .Text = strFindText
        Debug.Print .Text
        .Forward = True
        .Wrap = wdFindStop
        .MatchWildcards = True
        .Execute
    End With
End Function
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15587
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Locating square brackets in wildcard Find

Post by ChrisGreaves »

HansV wrote:
16 Mar 2022, 20:05
Why not use

Code: Select all

        strFindText = "\" & Left(strEmbrace, 1)
(snip!)
Because, Dear Hans,

Code: Select all

Function FindNestedStatement(sel As Selection, strEmbrace As String)
    ' https://eileenslounge.com/viewtopic.php?p=293581#p293581
    Dim strFindText As String
    With sel.Find
        .ClearFormatting
        strFindText = "\" & Left(strEmbrace, 1)
        strFindText = strFindText & "*"
        strFindText = strFindText & "\" & Right(strEmbrace, 1)
        .Text = strFindText
        Debug.Print .Text
        .Forward = True
        .Wrap = wdFindStop
        .MatchWildcards = True
        While .Execute
        
        Wend
    End With
End Function
with its while/wend loop lets me see my way towards a recursive process.
JSMill has cases of nested footnotes within parenthesized statements that contain smart-quote quotations which contain single-quote strings which contain references to footnotes which ...

All this is leading to a nested parsing of text, like my nesting procedures for VBA code, or WSChurchill's way of writing out and rehearsing his off-the-cuff speeches.

But I suspect that the answer you were looking for was "because I didn't know enough about this stuff as you do", and I'm not going to give you the satisfaction of knowing that.
Thanks Hans :clapping: :chocciebar: :cheers:
There's nothing heavier than an empty water bottle

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Locating square brackets in wildcard Find

Post by macropod »

To Find all text between matching brackets, parentheses and braces, all you need are wildcard Find expressions like:
.Text = "\([!\(]@\)"
.Text = "\{[!\{]@\}"
.Text = "\[[!\[]@\]"
To Find expressions between matched pairs of double quotes, be they smart quotes or ordinary quotes, you might use:
.Text = "[“""]*[""”]"
The limitation, of course, is that someone might have messed up their use of smart quotes & ordinary quotes...
Paul Edstein
[Fmr MS MVP - Word]