For example, there is a string like

"\"C:\\Program Files (x86)\\Microsoft Office\\Office15\\POWERPNT.EXE\" \"C:\\Users\\Test\\AppData\\Local\\Microsoft\\Windows\\INetCache\\1234\\Презентация.pptx\" /ou \"\"" 

Is there some general way to extract entities from it that are file names? I tried to use regulars, but the gaps in the path confuse them. For example:

 ^(?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w.$]+)\\(?:[\w]+\\)*\w([\w.])+ 

Works for simple cases, but not for the example described above. Perhaps, there is some kind of library for Go for such tasks, or you can somehow tweak my regular calendar.

  • spaces do not fall under \w . so first carefully parse the parameters, dividing them into spaces, of course without considering the spaces inside the quotes. And then among the parameters to look for something similar to the path - Mike
  • one
    What determines the "file name"? POWERPNT.EXE also a file. - Ainar-G 5:06
  • If file names can only be in quotes, then the regular expression should just take lines between the quotes. Well, there already on what is a file, and what does not depend. Well, and so on. Not enough data. And yes, this line is best presented in backquotes so that there is less garbage. - Ivan Black

1 answer 1

This expression:

 (?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w]+)\\(?:[\w\s\(\)]+\\)+([\wА-Яа-я\.\s]+) 

selects all the file names from the string. Those. "POWERPNT.EXE" and "Presentation.pptx". If you need only one of them, you need to correct the expression a little.