Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
192
rated 0 times [  197] [ 5]  / answers: 1 / hits: 15444  / 14 Years ago, fri, june 25, 2010, 12:00:00

I'm trying to match URLs with wildcards in them to actual URLs. For example:



http://*google.com/*


Needs to match



http://maps.google.com


And



http://www.google.com/maps


What would be the best way of going about this?



I've tried using a regular expression and that works fine when I manually program it but I'm not sure whether it's possible to dynamically generate regular expressions or if that would be the best practice in this situation.



/(http|https)://.*.?google.com/?.*/i


Thanks very much.


More From » regex

 Answers
164

Replace all occurrences of * in the pattern with [^ ]* - it matches a sequence of zero or more non-space characters.



Thus http://*google.com/* will become http://[^ ]*google.com/[^ ]*



Here is a regular expression to do the task:



regex = urlPattern.replace(/*/g, [^ ]*);

[#96412] Monday, June 21, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyaleenag

Total Points: 678
Total Questions: 121
Total Answers: 105

Location: Papua New Guinea
Member since Thu, Jul 9, 2020
4 Years ago
harleyaleenag questions
Thu, May 5, 22, 00:00, 2 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
;