JavaScript RegExp与标志“ s”和“ g”匹配

时间:2019-09-04 08:11:30

标签: javascript regex

我正在尝试在包含JavaScript上的换行符和空格的文本中匹配正则表达式。这是我的代码:

$(document).ready(function(){
  var text = $('.main').text();
  var output = $('.output');
 
  var regex = /\*\*\*.*?\*\*\*.*?\*\-\*\*.*?\*\*\*/g;
  var matches = regex.exec(text);
  var i = 0;
  
  while (result = regex.exec(text)) {
    console.log(result);
  }
  
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="main">
  <p>***'g':Meaning***<br />
  ***{{2}}:Yep***<br />
  ***{{2}}:True***<br />
  <br />
  Lorem ipsum dolor sit amet
  <br />
  <br />
  *-**{{2}}:True***<br />
  *-**{{2}}:Yep***<br />
  *-**'s':Meaning***<br />
  <br />
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</div>

但是使用****-**match():Meaning***:Meaning***标志不会返回匹配项。由于换行,我可以与****-**{{2}}:True***:Meaning***进行比赛。

我正在尝试获取exec()/qqq.*?qqq.*?qwq.*?qqq/s 之间的表达式。首先,我使用了qqqLOREMqqq Lorem ipsum dolor sit amet epictetus qqqANOTHERLOREMqqq Something something something qwqANOTHERLOREMqqq consectetur epilis qwqLOREMqqq Etiam ut felis molestie, tempor leo sit amet, pellentesque lorem. Sed consequat ut dui et mollis. Nulla sagittis vel felis id viverra. 函数,但是它只返回qqqLOREMqqqqwqLOREMqqq之间的第一个匹配项。然后搜索它,找到要迭代的qqqLOREMqqq函数。

我不知道如何找到合适的比赛。这是codepen

编辑

我正在编辑,因为这很困难并且需要花费时间来理解上面的代码。

我的正则表达式是:

qwqANOTHERLOREMqqq

文字是:

<input type="date" v-model="selectedDate" class="dateclass" :placeholder="new Date().toLocaleDateString()">

我想获取((* block docclass *)) \documentclass[11pt,a4paper,prb]{article} \usepackage{placeins,booktabs,array,tabularx,xparse,authblk} \AtBeginDocument{ \let\oldtabular\tabular \renewcommand{\tabular}{\tiny\oldtabular} } ((* endblock docclass *)) <?xml version="1.0" encoding="UTF-8"?> <proxy name="ProxyWithBasicAuth" startOnLoad="true" trace="disable" transports="https" xmlns="http://ws.apache.org/ns/synapse"> <target> <endpoint name="endpoint_urn_uuid_xxxxxxxx-yyyy-zzzz-1111-234567892345"> <address trace="disable" uri="https://here.goes.the.uri.of.the.ws.endpoint"/> </endpoint> <inSequence> <property value="this_is_the_username" name="username" scope="default" type="STRING"/> <property value="this_is_the_password" name="password" scope="default" type="STRING"/> <property expression="fn:concat($ctx:username,':',$ctx:password)" name="credentials" scope="default" type="STRING"/> <property expression="fn:concat('Basic ', base64Encode($ctx:credentials))" name="Authorization" scope="transport" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/> </inSequence> <outSequence> <send/> </outSequence> <faultSequence/> </target> </proxy> 之间的文本,但是它需要from scrapy.selector import Selector response = Selector(text='<div class="gameListRowItemName ellipsis ">Counter-Strike: Global Offensive</div> == $0') # with css selectors print('Css:',response.css("div.gameListRowItemName::text").extract()) # with xpath selectors print('Xpath:',response.xpath('//*[contains(@class,"gameListRowItemName")]/text()').extract()) Css: ['Counter-Strike: Global Offensive'] Xpath: ['Counter-Strike: Global Offensive']

0 个答案:

没有答案