简体   繁体   English

在Rails中使用gsub从链接中提取特定文本

[英]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" 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" 1)JobID其中“ 250920”

2)JobTitle which is "office junior" 2)“办公室初级”的工作职称

Is this possible by using gsub will I be able to get only those text from the link? 通过使用gsub可以做到这一点,我将只能从链接中获取那些文本吗?

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

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

result[1] #JobID

result[2] #JobTile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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