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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.