Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

javascript - 来自regex101的javascript regex不匹配[重复](javascript regex from regex101 is not matching [duplicate])

I need to replace the wte_embed_trips_width = "100%" in the following string.

(我需要在以下字符串中替换wte_embed_trips_width = "100%" 。)

<script type="text/javascript">
    var wte_embed_trips_width = "100%"; 
    var wte_embed_trips_height = "500px"; 
    var wte_embed_trips_param = "ids"; 
    var wte_trp_embed_id = "1526"; 
    var wte_embed_source_site = "http://wp-travel-engine.test/"; 
    var wte_embed_type = "wte_trips_embedder_trips"; 
    var wte_embed_ids_string = "543,547,532"; 
    var wte_embed_layout = "grid"; 
    var wte_embed_posts_num = "false";
</script>
<script src="http://wp-travel-engine.test/wp-content/plugins/wte-trips-embedder/assets/js/wpte-embed-handler.js" type="text/javascript"></script>
<div style="--aspect-ratio: 16/9;" id="wte-trips-embedder-1526"></div>

I am using /wte_embed_trips_width = "\d+(%{1}|(px){1})"/gmui regular expression works perfectly in regex101.com but when I use it in acutal, it doesn't work.

(我正在使用/wte_embed_trips_width = "\d+(%{1}|(px){1})"/gmui正则表达式在regex101.com中可以正常使用,但是当我在acutal中使用它时,它将无法正常工作。)

var regexp = new RegExp('wte_embed_trips_width = "d+(%{1}|(px){1})"', 'gmui');

var a = `<script type="text/javascript">var wte_embed_trips_width = "100%"; var wte_embed_trips_height = "500px"; var wte_embed_trips_param = "ids"; var wte_trp_embed_id = "1526"; var wte_embed_source_site = "http://wp-travel-engine.test/"; var wte_embed_type = "wte_trips_embedder_trips"; var wte_embed_ids_string = "543,547,532"; var wte_embed_layout = "grid"; var wte_embed_posts_num = "false";</script><script src="http://wp-travel-engine.test/wp-content/plugins/wte-trips-embedder/assets/js/wpte-embed-handler.js" type="text/javascript"></script><div style="--aspect-ratio: 16/9;" id="wte-trips-embedder-1526"></div>`;

regexp.test(a); // returns false. shoud have return true according regex101.com

The link to regex is https://regex101.com/r/L67WX4/2/

(到正则表达式的链接是https://regex101.com/r/L67WX4/2/)

  ask by Sagar Bahadur Tamang translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...