简体   繁体   English

使用正则表达式获取Google搜索的最后一个关键字

[英]Get last keyword of a Google search with a Javascript regex

I'm using a javascript regex to extract the keyword from a Google search. 我正在使用JavaScript正则表达式从Google搜索中提取关键字。 ( Extract keyword from Google search in Javascript ) 使用Javascript从Google搜索中提取关键字

The answer from the previous post works great except some cases when you do several searches in a row 上一篇文章的答案非常有效,除了某些情况下您连续进行几次搜索

ie I searched for the keyword "car" and I got some results, then I did another search for the keyword "plane" and I got the url ( http://www.google.com/search?q=car&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:fr:official&client=firefox-a#sclient=psy&hl=en&client=firefox-a&hs=P4M&rls=org.mozilla:fr%3Aofficial&source=hp&q=plane&aq=f&aq ... ). 也就是说,我搜索了关键字“汽车”,然后得到了一些结果,然后又搜索了关键字“飞机”,然后得到了网址( http://www.google.com/search?q=car&ie=utf- 8&oe = utf-8&aq = t&rls = org.mozilla:fr:official&client = firefox-a#sclient = psy&hl = zh-CN&client = firefox-a&hs = P4M&rls = org.mozilla:fr%3Aofficial&source = hp&q = plane&aq = f&aq ...)。 For this search I get the keyword "car" and then the keyword "plane" and what I'd like is only the last keyword ("plane"). 对于此搜索,我得到了关键字“ car”,然后得到了关键字“ plane”,而我想要的只是最后一个关键字(“ plane”)。

Does someone know how to correct the regex from the previous to make it work ? 有人知道如何从前者更正正则表达式以使其正常工作吗?

您提到的帖子中的JavaScript对我来说效果很好,并且仅返回“ plane”,请参见此处: http : //jsfiddle.net/EWx4S/

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

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