Need to find and move url text to another word document

I need to find url text(with & without hyperlink) using multiple type of RegEx then if it's found import all url text to new word document from current active document. Is it possible in word VBA? Can anyone ​suggest code?
RegEx Types
Type 1: with https://
Type 2: without https://
Type 3: with www.
Type 4: without www.
Steven ReynoldsAsked:
Who is Participating?
Rgonzo1971Connect With a Mentor Commented:

pls try
Sub RegexSimple()
Dim regex As Object
Dim arrSentences()
Idx = -1
Set regex = CreateObject("VBScript.RegExp")

    With regex
        .Global = True
        .IgnoreCase = False
        .Pattern = "\b(?:https?:\/\/)?(?:www\.)?(?=\w+\.)[a-zA-Z0-9.\/]+\b"
    End With
    Set Mtchs = regex.Execute(ActiveDocument.Range.Text)
    For Each Mtch In Mtchs
        Idx = Idx + 1
        ReDim Preserve arrSentences(Idx)
        arrSentences(Idx) = Trim(Mtch)
    ActiveDocument.Range.Text = Join(arrSentences, vbCrLf)
Set regex = Nothing
End Sub

Open in new window

Steven ReynoldsAuthor Commented:
Hi Rgonzo1971
Thank you for your assist. Above code is working well but I need to retain paragraph style, font forecolor, & bold style as per original document. Is it possible?
Steven ReynoldsAuthor Commented:
I need to retain all styles like paragraph style, list style, etc., & font colors, & bold style as per original document. Is it possible?
Sorry can't help further
A Solution
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.