-1

I'm having the hardest time with javascript regex, can't figure out how to match my url:

http://localhost:11111/#!/quote/18283 

and

http://www.myurl.com/#!/quote/23834

with the same regex.

I just don't understand the regex rules that well.

CSᵠ
  • 10,049
  • 9
  • 41
  • 64
  • 4
    What have been your attempts so far? – Jerry Aug 12 '13 at 20:39
  • FYI - regex is entirely independent of other languages. Different languages use it differently, but something that is a correct RegEx match will be a correct RegEx match in Java, Javascript, C#, and thousands of others. – Xynariz Aug 12 '13 at 20:41
  • possible duplicate of [Getting parts of a URL (Regex)](http://stackoverflow.com/questions/27745/getting-parts-of-a-url-regex) – Wrikken Aug 12 '13 at 20:44
  • 1
    What are you trying to achieve? Are you trying to extract some data from the URL? Anyway, `^http://\w+(\.\w+)*(:\d+)?/#!/(\w+/?)+$` would match both and all other urls having that structure. – plalx Aug 12 '13 at 20:52

2 Answers2

2

http://[\w\d\.:]+/#!/quote/\d{5} - but obviously that is without any other context. I don't know what your negative cases are. Which parts of the URLs are important, etc, etc.

CodeBeard
  • 515
  • 3
  • 10
1

One hint I can add is, if you are only looking to match a specific domain.com with localhost you can use alternation (either/or) with the pipe | symbol like (this is just for one portion of the regex:

((www\.)?myurl\.com|localhost:\d+)
Neil Neyman
  • 2,116
  • 16
  • 21