Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

regex - Is there any python method that can make valid URL from non-valid URL?

I try to Remove extra char from this URL(Please watch snapshot)

https://test.com/ABC]VR?

URL Snapshot

but I can't make it perfect URL format, and I try this code

    import re

    p = re.compile(r'(?:w*://)?(?:.*?.)?(?:([a-zA-Z-1-9]*).)?([a-zA-Z-1-9]*.[a-zA-Z]{1,}).*')

    domain = 'https://test.com/ABC]VR?'

    print(p.match(domain))

Code Snapshot

but still, it gives output

https://test.com/ABC]x1dVx1dR?x1d

where I need output like

https://test.com/ABCVR

So, is there any build-in method in python to do that? or if need to make manually any way without regular expression? if no way without regular expression then how to do that with a regular expression?

Thank you.

question from:https://stackoverflow.com/questions/65931683/is-there-any-python-method-that-can-make-valid-url-from-non-valid-url

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...