2017-12-19 4 views
0

URL은 단지 PID 매개 변수 값을 선택해야정규식 추출물 정확한 (포함되지 않음) URL의 PARAM 값

example.com/test?pid=123 

example.com/test?test=ttt&pid=123 

example.com/test#test=ttt&pid=123 

example.com/test?pid=123&test=ttt& 

example.com/test?xxxpid=123&test=ttt& //should not select because it has xxx prepanded. 

수 있습니다. 나왔어

[^?]+(?:\?pid=([^&]+).*)? 

그러나 문제가있다.

example.com/test?gdsfg=sdfasdfa&pid=123 

답변

0

선택 PID 파라미터 값

.+[?&]pid=([^=?&\s]+) 

필요한 값이 1에서 그룹에

https://regex101.com/r/E1yHVY/11

+0

url.replace을 캡처 (regexARr [0] " ---- ")는 URL 전체가 아니라 매개 변수 만 반환합니다. 어떻게 URL 전체를 반환 할 수 있습니까? 선택 그룹과 관련이 있습니까? – serkan

+0

@ serkandemirel0420,하지만 * select pid 매개 변수 값 *을 작성했습니다. 위의 패턴은'pid' 매개 변수를 포함하는 전체 URL과 일치해야합니다. – RomanPerekhrest

+0

예, 바꾸기 기능에서 사용해야한다고 명시 했어야했는지 알 수 없습니다. – serkan