Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

python - Generic Regex building to match URL routes based on its constant and variable parts

Suppose we are intending to scrape a domain, foo.com, which virtually contains many external sublinks, such as:

  • /bar/1020/biz?foo=qwe
  • /bar/3001/biz?foo=rty
  • /bar/12033/biz?foo=abc
  • /bar/1020/biz?foo=xyz

The idea is to apply a difference checker algorithm which yields a generic regex that matches the above routes based on their constant and variable parts.

In this case, the perfect regex would be:

^/bar/d+/biz?foo=.*?$

Which in other words implies:

/bar/{any number}/biz?foo={any string}

What is the best approach to achieve the following, given that a dataset of 100-ish routes are provided?

question from:https://stackoverflow.com/questions/65842460/generic-regex-building-to-match-url-routes-based-on-its-constant-and-variable-pa

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...