Results 1 to 9 of 9
  1. #1
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post

    Wild Card Bold Between 2 Characters in a string

    Hello folks,

    I have a document that has html in it.

    I am trying to bold between 2 characters in the HTML

    Bold anything between first character angle and < lowercase d

    Bold everything including the last >

    In between there may be letters and Numbers and " quotation marks and an equal sign



    This is what I have so far after failure of other methods - this doe not work


    <[[d]A-z0-9\"\=<>]+>


    it should bold

    <div class="red"> Hello
    <div class ="something"> Hello

    I have tried a lot of combinations and cant seem to fix this

    I appreciate the assistance from the resident pros on regex wildcards

    thanks

    pb

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    PB,

    This RegEx string: [COLOR="#0000FF"][SIZE=3](\<[Dd])([A-Za-z0-9 ="]{2,})(\>)[/SIZE][/COLOR]

    Should do the trick.

    Document Before:
    RegExBefore.PNG

    Setup of S&R:
    RegExResults.PNG

    Document After:
    RegExAfter.PNG

    HTH
    Last edited by RetiredGeek; 2016-05-03 at 16:33. Reason: Added 0-9 to second grouping per post #4
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. The Following User Says Thank You to RetiredGeek For This Useful Post:

    pb89 (2016-05-03)

  4. #3
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post
    RG,

    nice to see you again.

    I dont know how you did it but its sings beautifully, if there was an idiom to explain my elation.

    (\<[Dd])([A-Za-z ="]{2,})(\>)

    Wow I am really impressed, i have spent hours on online regex testers, had to give up in the end.

    Smashing

    thanks ever so much

    have a fantastic day!!

    pb

    oh and as always thanks for the screen shots - i really did have to look at it 3 times

  5. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    PB,

    Here's an explaination of the RegEx:

    • () are used to group items, used in the replace command. Note there are 3 groupings thus the \1\2\3 in the example.
    • \ is the Escape character, e.g. treat the following character as a normal character not a RegEx special meaning.
    • < RegEx Special Start of Word and of course > end of word this is why they are Escaped in the sample in the previous post since we want to fine the HTML Tags.
    • [ ] Any of the included characeters/character Ranges, indicated by -, e.g.: A-Z
    • {n,n} Find at least (1st n) this many of the items in the previous group, (2nd n) find no more than this many occurrences of previous group. Thus in our example it must find at least 2 "<d" and we don't care how many thus no limit specified.


    OOPS! I just realized I forgot the 0-9 range in the second grouping!

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    You could use just:
    Find = \<[Dd][!\>]@\>

    I can't see the point of the grouping or the need for all the other character testing in the expression.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. The Following User Says Thank You to macropod For This Useful Post:

    pb89 (2016-05-03)

  8. #6
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post
    Paul & RG,

    thank you ever so much.

    I try to avoid regex and wild cards - I start off full of hope and soon enough Ive got it all back wards,
    but as we know they are an occupational hazard to the uninitiated

    I am very obliged

    Good Evening to all

    pb

  9. #7
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Quote Originally Posted by macropod View Post
    You could use just:
    Find = \<[Dd][!\>]@\>
    Paul,

    This intrigued me so I gave it a try but got this:
    PaulRegex.PNG

    Am I missing something?
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  10. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Did you check the 'use wildcards' option?
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  11. #9
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Paul,

    HomerDOH.png

    Works Like a Charm!
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •