[英]javascript regex fails with double quotes
I have this js 我有这个js
var race = {
"id": Number( matches[ i ].match( /gt5bspec\.selectEvent\("/(\d+/\d+)"\)/ )[ 1 ] ),
"laps": Number( matches[ i ].match( /<dd class="lap">.+?(\d+)/ )[ 1 ] ),
"maxEntrants": Number( matches[ i ].match( /entry_max.+?\/>(\d+)<\/dd>/ )[ 1 ] ),
"time": Number( matches[ i ].match( /common\/time\/(\d+)\.png/ )[ 1 ] ),
};
its failing SyntaxError: illegal character on the "id" line I am guessing due to the quotes in the expression. 由于表达式中的引号,我猜测其失败的SyntaxError:“ id”行上的非法字符。
here is an example string that is used for the search 这是用于搜索的示例字符串
<dl class="remote_event_list"> <dd class="course_logo"><img src="/common/images/gt5/remote_race/common/courselogo/ed2539fe892d2c52c42a440354e8e3d5.png" width="84"></dd> <dd class="race_info_minute"><img src="/common/images/gt5/remote_race/common/time/20.png" width="80" height="54" alt=""></dd> <dd class="entry_max"><img src="/common/images/gt5/remote_race/entry/icon_driver.png" width="20" />16</dd> <dd class="lap"><span>Vuelta(s):</span> 12 (en torno a 20 minutos)</dd> <dd class="car_image"> <img src="/common/images/gt5/car/thumbnail/0a712318b3b8acc70daeb1ff71d40140.png" width="178" /> </dd> <dd class="link"><a href="javascript:void(0);" onclick='gt5bspec.selectEvent("/116/1035200")' title="Abt Audi TT-R Touring Car '02 / Circuito de Madrid"> </a></dd></dl>
I am trying to match the group 1 value of /116/1035200 我正在尝试匹配/ 116/1035200的组1值
Thanks 谢谢
//-----------------------v
/gt5bspec\.selectEvent\("/(\d+/\d+)"\)/
I've marked the unescaped slash. 我标记了未转义的斜线。 If you want literal slash here, use \\/
. 如果要在此处使用斜杠,请使用\\/
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.