How to disassemble a string with CaptureGroup “(.+?:[\/\\]+)”?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 06:47:56

问题


A given string:

dec:/file1.texdec:/file2.srcdec:/file3.ltx\ndec:/file4.dtxdec:/file5.insdec:/file6.src

contains concatenated file paths.

(The length of the volume name (here: dec) is variable. Pay attention to the line break in the string.)

With the RegExp (.+?:[\/\\]+) (without g and without m options) I get the CaptureGroup \1 dec:/.

(If the volume name is only c the CaptureGroup contains c:/. With path containing \ instead of / the CaptureGroup also contains dec:\ or c:\.)

How can I match the substrings:

dec:/file1.tex
dec:/file2.src
dec:/file3.ltx
dec:/file4.dtx
dec:/file5.ins
dec:/file6.src

with this CaptureGroup (.+?:[\/\\]+)?

I have prepared the following DEMO


回答1:


This is what you want it ?(.+?:[\/\\]+)(?:(?!\1).)*

This is a demo on regex101.



来源:https://stackoverflow.com/questions/57211051/how-to-disassemble-a-string-with-capturegroup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!