简体   繁体   中英

extracting particular text from link using gsub in rails

I have a link by this text,

s= "http://xyz.com/Getid.ashx?JobID=250920&JobTitle=office+junior&seswitch=1&lid=801&AVSDM=2012-11-22+11%3a33%3a00"

I need to extract two information from this link

1)JobID which "250920"

2)JobTitle which is "office junior"

Is this possible by using gsub will I be able to get only those text from the link?

您可以尝试使用.match与正则表达式:

result = s.match(/JobID\\=(\\d+).+JobTitle\\=([a-zA-Z+0-9]+)\\&/)

result[1] #JobID

result[2] #JobTile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM