This should do it:
> txt
[1]
"\nhttp://www.mysite.com/system/empty.asp?P=2&VID=default&SID=421384237289476&S=1&C=18631"
[2]
"\nhttp://www.mysite.com/system/empty.asp?P=123&VID=default&SID=421384237289476&S=1&C=18643"
[3]
"\nhttp://www.mysite.com/system/empty.asp?P=342&VID=default&SID=421384237289476&S=1&C=18634\n"
[4]
"\nhttp://www.mysite.com/system/empty.asp?P=232&VID=default&SID=421384237289476&S=1&C=18645"
[5]
"\nhttp://www.mysite.com/system/empty.asp?P=2345&VID=default&SID=421384237289476&S=1&C=18254"
[6]
"\nhttp://www.mysite.com/system/empty.asp?P=257654&VID=default&SID=421384237289476&S=1&C=18732"
[7]
"\nhttp://www.mysite.com/system/empty.asp?P=22&VID=default&SID=421384237289476&S=1&C=18637"
[8]
"\nhttp://www.mysite.com/system/empty.asp?P=2463&VID=default&SID=421384237289476&S=1&C=18575\n"
> gsub("^.*asp.P=([[:digit:]]+).*$", '\\1', txt)
[1] "2" "123" "342" "232"
"2345" "257654" "22"
"2463">
On 8/13/07, Lauri Nikkinen <lauri.nikkinen at iki.fi>
wrote:> Dear R-users,
>
> How do I extract numbers between asp?P= and &VID from my txt vector? I
have
> tried grep function with no luck.
>
> txt <- c("
>
http://www.mysite.com/system/empty.asp?P=2&VID=default&SID=421384237289476&S=1&C=18631",
> "
>
http://www.mysite.com/system/empty.asp?P=123&VID=default&SID=421384237289476&S=1&C=18643",
> "
>
http://www.mysite.com/system/empty.asp?P=342&VID=default&SID=421384237289476&S=1&C=18634
> ","
>
http://www.mysite.com/system/empty.asp?P=232&VID=default&SID=421384237289476&S=1&C=18645",
> "
>
http://www.mysite.com/system/empty.asp?P=2345&VID=default&SID=421384237289476&S=1&C=18254",
> "
>
http://www.mysite.com/system/empty.asp?P=257654&VID=default&SID=421384237289476&S=1&C=18732",
> "
>
http://www.mysite.com/system/empty.asp?P=22&VID=default&SID=421384237289476&S=1&C=18637",
> "
>
http://www.mysite.com/system/empty.asp?P=2463&VID=default&SID=421384237289476&S=1&C=18575
> ")
>
> The result should be like
> 2
> 123
> 342
> 232
> 2345
> 257654
> 22
> 2463
>
> Thanks,
> Lauri
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?