如何解决在Javascript中使用正则表达式的问题

how to solve using regular expression in Javascript

本文关键字:正则表达式 问题 Javascript 何解决 解决      更新时间:2023-09-26

我正在从json中获取类似的android url

"https:'/'/play.google.com'/store'/apps'/details?id=com.lego.starwars.thenewyodachronicles&hl=en"

现在我只想要上面URL中的包名称:->"com.lego.starwars.newyodachronicles"

如何在javascipt 中使用正则表达式来解决它

提前Thanx:)

您需要使用前瞻性。

[^=&]+(?=&)

代码:

> "https://play.google.com/store/apps/details?id=com.lego.starwars.thenewyodachronicles&hl=en".match(/[^=&]+(?=&)/g)
[ 'com.lego.starwars.thenewyodachronicles' ]
^.*?=(['w.]+).*$

试试这个。请参阅演示。

http://regex101.com/r/kM7rT8/9