Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript,如何使用正则表达式解析字符串_Javascript_Regex - Fatal编程技术网

Javascript,如何使用正则表达式解析字符串

Javascript,如何使用正则表达式解析字符串,javascript,regex,Javascript,Regex,我有多个{Start:SomeName}}的字符串,我需要用 和{End:SomeName}}到 我试着像这样使用replace{{Start:,'来替换像字符串这样的结构化内容,只需要取一个片段并拆分为变量可能更容易: 让s={{Start:SomeName}} 让[side,name]=s.slice2,-2.split':' 让标记=`` console.logtag有了像字符串这样的结构,只需要取一个片段并拆分为变量可能更容易: 让s={{Start:SomeName}} 让[sid

我有多个{Start:SomeName}}的字符串,我需要用 和{End:SomeName}}到


我试着像这样使用replace{{Start:,'来替换像字符串这样的结构化内容,只需要取一个片段并拆分为变量可能更容易:

让s={{Start:SomeName}} 让[side,name]=s.slice2,-2.split':' 让标记=``
console.logtag有了像字符串这样的结构,只需要取一个片段并拆分为变量可能更容易:

让s={{Start:SomeName}} 让[side,name]=s.slice2,-2.split':' 让标记=``
console.logtag类似这样的东西应该可以做到:

const input={{Start:SomeName}{{Start:SomeName}}{{End:SomeName}}{{End:SomeName}} const result=input.replace/{{.+?:.+?}}/g,
console.logresult像这样的东西应该可以做到:

const input={{Start:SomeName}{{Start:SomeName}}{{End:SomeName}}{{End:SomeName}} const result=input.replace/{{.+?:.+?}}/g,
console.logresult可能与此类似

const str={{Start:SomeName}}你好{{End:SomeName}}{{{Start:AnotherName}}}世界{End:AnotherName}}; const replaced=str.replace/{{Start:\w+}}.{{End:\1}}/g,{u},name,content=>{ 返回`${content}`; };
console.logreplaced;可能是类似于这些内容的东西

const str={{Start:SomeName}}你好{{End:SomeName}}{{{Start:AnotherName}}}世界{End:AnotherName}}; const replaced=str.replace/{{Start:\w+}}.{{End:\1}}/g,{u},name,content=>{ 返回`${content}`; }; 控制台。日志被替换; 结果={{Start:SomeName}}{{Start:SomeName}{{End:SomeName}}{{End:SomeName}}。替换/{{Start:\w+}}{{124;{End:\w+}}/g{ ifa[1]{ 返回`` } 否则{ 返回`` } } 控制台。日志结果 结果={{Start:SomeName}}{{Start:SomeName}{{End:SomeName}}{{End:SomeName}}。替换/{{Start:\w+}}{{124;{End:\w+}}/g{ ifa[1]{ 返回`` } 否则{ 返回`` } }
console.logresult您可以使用类似RegEx的命令

var re=/\{Start:.*\}.*\{End:.*\}/g; var chaine={{Start:SomeName}}你好世界{{{End:SomeName}} var输出=chaine.replace,$2;
console.logoutput您可以使用类似RegEx的命令

var re=/\{Start:.*\}.*\{End:.*\}/g; var chaine={{Start:SomeName}}你好世界{{{End:SomeName}} var输出=chaine.replace,$2;
console.logoutput您可以添加一个您正在处理的确切字符串的示例。它是这些标记的多个吗?还是有其他文本交织在一起?让s={{Start:SomeName}}{{Start:SomeName}{{{End:SomeName}{{End:SomeName}}{例如,您可以添加一个您正在处理的确切字符串的示例。它是这些标记的倍数吗?还是有其他文本交织在一起?例如,让我们={{Start:SomeName}}{{Start:SomeName}}{{{End:SomeName}}{{{End:SomeName}}{