0

I 've a File structure "solution/"

Need a reg exp to match all the files under "solution/" Excluding .img files in the path "solution/tree/changes/sample.img"

I tried below it but of not worked

^solution\/tree\/changes\/((?!.img).)*$

Thanks in advance

melpomene
  • 84,125
  • 8
  • 85
  • 148
Raj
  • 1
  • 1
  • Specify the programming language. Regexps are different in some programming languages – Valeriy Nov 06 '17 at 14:40
  • We are actually providing an JSON input with regular expression, to copy files from the location. Ex: "^solution\/tree\/changes\/((?!.img).)*$" – Raj Nov 06 '17 at 14:45
  • `.img` matches any char followed with `img`. So, you need to escape the `.` to make it match a literal dot. You may also add `$` after `\.img` to make sure you only disallow it at the end of the string, and then your tempered greedy token will turn into a simple lookahead (`((?!.img).)*$` => `(?!.*\.img$).*`) – Wiktor Stribiżew Nov 06 '17 at 14:47

2 Answers2

0

You did not mention language, but this should work

^solution\/tree\/changes\/(?!.*\.img).*$

see regex101 demo: https://regex101.com/r/Y7znBy/1

Important! You need to set multilineflag

Fallenhero
  • 1,563
  • 1
  • 8
  • 17
  • I dont understand. So this is not working for you? – Fallenhero Nov 06 '17 at 14:49
  • 'My Exact requirement is I 've following file structure solution/moon/ solution/tree/anomoly/ solution/tree/enquiry/ solution/tree/changes/space.img solution/tree/changes/mine.txt I've to parse a json file as input with regular expression to copy all the files in the above structure except solution/tree/changes/space.img JSON Input which I've tried is "^solution\/(?!tree\/).*\/*", "^solution\/tree\/(?!changes\/).*\/*", "^solution\/tree\/changes\/((?!.img).)*$"' – Raj Nov 06 '17 at 14:56
0

@Fallenhero My Exact requirement is I 've following file structure

solution/moon/
solution/tree/anomoly/
solution/tree/enquiry/
solution/tree/changes/space.img
solution/tree/changes/mine.txt

I've to parse a json file as input with regular expression to copy all the files in the above structure except solution/tree/changes/space.img

JSON Input which I've tried but didn't work

"^solution\/(?!tree\/).*\/*",
"^solution\/tree\/(?!changes\/).*\/*",
"^solution\/tree\/changes\/((?!.img).)*$"

Could you please provide your ideas

Raj
  • 1
  • 1