Results 1 to 5 of 5

Thread: looking for regex pattern

  1. #1

    Lightbulb looking for regex pattern

    Hi all,

    i hope to find someone is good enough for this simple regex pattern and i don't prefer to use wildcards

    i need to find those text below:


    and when find replace it with:

    resolved="true">[MT Score:{6}] Additional Comment:

    and whatever the number is in the searched segment i want it to be replace in the another segment with same conetxt.

    for ex:

    resolved="false">6------> resolved="true">[MT Score:{6}] Additional Comment:
    resolved="false">4 ------>resolved="true">[MT Score:{4}] Additional Comment:
    resolved="false">77 ------>resolved="true">[MT Score:{77}] Additional Comment:
    resolved="false">25 ------>resolved="true">[MT Score:{25}] Additional Comment:

    Thanks in advance for anyone that can help


  2. #2
    VBAX Expert
    Sep 2016
    .Pattern = "(resolved=""false""\>)(\d{1,})"
    Sub test()
        Dim r As Range
        Set r = ActiveDocument.Range
        With r.Find
            .Text = "(resolved=""false""\>)([0-9]{1,})"
            .Replacement.Text = "\1[MT Score:{\2}] Additional Comment:"
            .MatchWildcards = True
            .Execute Replace:=wdReplaceAll
        End With
    End Sub
    Last edited by mana; 11-01-2019 at 09:55 PM.

  3. #3
    What's the problem with wildcards?

    \1"true">[MT Score:{\2}] Additional Comment:
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes

  4. #4
    thousands of thanks Mana for your generous help, it works well

  5. #5
    Hi Graham,

    your code works well too and it is nice of you to add another way. i preferred regex because it is more common on all tools unlike the wildcard and i don't have enough experience with it. but now i got your reference link for wildcards and that was another good help from you i guess i will try to know more about it.


Tags for this Thread

Posting Permissions

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