Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Reverse regexp a regexp?

by freakingwildchild (Scribe)
on Feb 12, 2010 at 19:52 UTC ( [id://822922]=note: print w/replies, xml ) Need Help??


in reply to Re: Reverse regexp a regexp?
in thread Reverse regexp a regexp?

This is possible by converting a regex into some sort of finite automaton and doing a traversal on it.

Perl would be my prefered choice in this though. The use of such would be great in creating examples in how regexes get processed.

This problem is a bit underspecified. For example, if you give me any sample of, say, 10 URLs

http://www.youtube.com/user/test1 http://www.youtube.com/user/test2 http://www.youtube.com/user/test3 http://www.youtube.com/user/test4 http://www.youtube.com/user/test5:
regex created: http://www.youtube.com/user/(.*)

http://be.apple.itunes.com/blabla/blabla/id/1543285432 http://us.apple.itunes.com/blabla/blabla/id/154328545 http://uk.apple.itunes.com/blabla/blabla/id/5532424342 http://be.apple.itunes.com/blabla/blabla/id/15432 http://be.apple.itunes.com/blabla/id/4324
regex created: http://(\d)+\.apple.itunes.com/blabla/blabla/id/(.*)

Replies are listed 'Best First'.
Re^3: Reverse regexp a regexp?
by Anonymous Monk on Feb 12, 2010 at 20:20 UTC

    Reread what Roboticus said. Your first example could just as easily have been http://www.youtube.com/user/test[1-5] and your second could have been http://(u[sk]|be)\.apple.itunes.com/blabla/blabla/id/(\d*)5(\d+).

    How do you make the choices? Once you can answer those questions, you'll be able to make some progress towards what you want.

      How do you make the choices? Once you can answer those questions, you'll be able to make some progress towards what you want.

      I'd say ... an algorithm of minimum requirements could do the trick here.

      for example:

      1. 10 url's of the same domain of a 95% "similarity" would be matched as "clean url".
      2. 100 url's of the same domain would give more weight
      3. The string detected has to be atleast 4 characters difference before it adds weight/validity
      4. Any others could be selected manually or kept in a cache till they offer a difference
      Some url's will be easier than some others (especially script url's); but most sites got a general structure, to be SEO friendly towards search engines; which would make most URL's a heaven to work with...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://822922]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found