PDA

View Full Version : [SOLVED:] looking for regex pattern



Ethen5155
11-01-2019, 07:54 AM
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:

resolved="false">6

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

Cheers

mana
11-01-2019, 09:41 PM
.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

gmayor
11-01-2019, 09:45 PM
What's the problem with wildcards?

Replace
(resolved=)"false"\>([0-9]{1,})
with
\1"true">[MT Score:{\2}] Additional Comment:

https://www.gmayor.com/replace_using_wildcards.htm

Ethen5155
11-02-2019, 03:17 AM
thousands of thanks Mana for your generous help, it works well

Ethen5155
11-02-2019, 03:21 AM
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 :thumb i guess i will try to know more about it.

Cheers