匹配URL的一部分,从结尾开始并回头

时间:2019-05-21 16:22:22

标签: javascript regex regex-lookarounds

使用正则表达式(及其JavaScript风格)如何匹配第一组URL,而不匹配第二组,然后反过来?

我全都可能从pi开始(他们都有)开始,然后在后面寻找正斜线和一些数字,但我承认我输了。

Group 1:

https://my.domain.com/?pi123=20&pi637=2
https://my.domain.com/?pi123=20&pi637=3
https://my.domain.com/?pi123=21
https://my.domain.com/?pi123=21&pi637=2
https://my.domain.com/?pi123=22
https://my.domain.com/p/mypage?pi7666=37
https://my.domain.com/p/mypagejonothing?pi1286=14
https://my.domain.com/hello/jo-nothing/?pi5676=1&pi8973=45
https://my.domain.com/hello/aword-anotherword-perhapsmore/f/words-words-stuff-stuff-stuff
https://my.domain.com/hello/aword-anotherword-perhapsmore/f/words-words-stuff-stuff-stuff#pi8765=2
https://my.domain.com/hello/aword-anotherword-perhapsmore/f/words-words-stuff-stuff-stuff?pi8765=2


Group 2:

https://my.domain.com/hello/aword-anotherword-perhapsmore/f/words-words-stuff-stuff-stuff/7654321/anyword-anyword-anyword-anyword-anyword-anyword-anyword
https://my.domain.com/hello/aword-anotherword-perhapsmore/f/words-words-stuff-stuff-stuff/7654321/anyword-anyword-anyword-anyword-anyword-anyword-anyword#pi2151=3
https://my.domain.com/hello/aword-anotherword-perhapsmore/f/words-words-stuff-stuff-stuff/7654321/anyword-anyword-anyword-anyword-anyword-anyword-anyword#pi2151=5
https://my.domain.com/hello/jo-nothing/f/word/123456/one-five-twelve-random-length45-3-1?pi2151=2
https://my.domain.com/hello/jo-nothing/f/yes-no-yes/54321/test-one-way#pi2151=2
https://my.domain.com/hello/jo-nothing/f/no-yes/123456/one-five-twelve-random-length45-3-1#pi2151=2

它必须具有JavaScript的正则表达式风格和两个单独的模式(一个与第一个URL匹配,然后与另一个组的第二个模式匹配)。

0 个答案:

没有答案