简体   繁体   English

如何在 JavaScript 中使用正则表达式查找字符串?

[英]How to find a string using a regular expression in JavaScript?

This is the string from which I need to do searching -这是我需要搜索的字符串 -

<bpmn:process id="Process_1" isExecutable="false">
<bpmn:task id="Task_15xgmrn" name="Select1Select5" extratask:entity="Select1" extratask:action="Select5"/>
<bpmn:extensionElements> <camunda_1:executionListener class="org.camunda.bpm.getstarted.loanapproval.MyTaskList" event="start"/> </bpmn:extensionElements>
<bpmn:task id="Task_0ditp3t" name="Select2Select6" extratask:entity="Select2" extratask:action="Select6" camunda_1:exclusive="false" camunda_1:asyncAfter="true" camunda_1:async="true" />
<bpmn:extensionElements> <camunda_1:executionListener class="org.camunda.bpm.getstarted.loanapproval.MyTaskList" event="start"/> </bpmn:extensionElements>
<bpmn:task id="Task_0ffkkda" name="Select2Select4" extratask:entity="Select2" extratask:action="Select4"/>
<bpmn:task id="Task_0p68hrl" name="Select3Select6" extratask:entity="Select3" extratask:action="Select6"/>
</bpmn:process>

And search result should be like this -而搜索结果应该是这样的——

<bpmn:task id="anything" name="anything" extratask:entity="anything" extratask:action="anything" />

all the occurrence of the result.所有发生的结果。

I have made some changes in the search string, some attributes have been added into the second "bpmn:task" tag.我对搜索字符串进行了一些更改,一些属性已添加到第二个“bpmn:task”标签中。 And I don't want that tag to be get selected in the search result.而且我不希望在搜索结果中选择该标签。

Am I correct that what you actually want to do is collect all the bpmn:task XML tags, because this can actually be as small as:我是否正确,您实际上想要做的是收集所有bpmn:task XML 标记,因为这实际上可以小到:

str.match(/<bpmn:task.+?>/g)

Or as the person in the comment pointed out或者正如评论中的人指出的那样

str.match(/<bpmn:task id=".*"\s*name=".*"\s*extratask:entity=".*"\s*extratask:action=".*"\s*\/>/g)

However if you want to anything more with the XML I do highly recommend using a parser.但是,如果您想对 XML 进行更多操作,我强烈建议您使用解析器。

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

相关问题 如何使用正则表达式验证Javascript中的字符串? - How to verify a string in Javascript using regular expression? 如何在带有url的正则表达式字符串的javascript中查找? - How to find in javascript with regular expression string from url? 怎么找 ” <script>” tag from the string with JAVASCRIPT/ regular expression - How to find “<script>” tag from the string with JAVASCRIPT/ regular expression 正则表达式以查找函数字符串是否为javascript - Regular Expression to find if a function string javascript 如何使用javascript正则表达式在字符串中最多允许3个空格 - how to allow upto 3 spaces in a string using javascript regular expression 如何使用JavaScript中的正则表达式以优美的方式提取字符串? - How to extract in elegant way the string using the regular expression in JavaScript? 如何使用javascript正则表达式从字符串中获取域 - How to get domain from a string using javascript regular expression JavaScript:如何使用正则表达式从URL中提取字符串 - JavaScript: How to pull out a string from a URL using a regular expression 如何在JavaScript中使用正则表达式提取句点(。)之后的字符串? - How to extract string after period (.) using regular expression in javascript? 使用Java中的正则表达式查找和更改div - Find and change a div using a regular expression in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM