Let me summarize your problem:
- url must be http/https/ftp
- url must have 1 directory before file name
- file name in url must be 32 alphanumeric character
Your attempt: ((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([0-9a-z]{32})
Test string:
Your approach is already correct. You just need to make sure that after those 32 characters, there's no more character. So you need to add $
in the end.
Also, the schema (http/https/ftp) is in capture group. That means if there's a schema (http/https/ftp), it will be captured, but it doesn't have to exist. So, just add a 1 quantifier to the schema capture group {1}
.
Answer: ((http[s]?|ftp):\/){1}?\/?([^:\/\s]+)((\/\w+)*\/)([0-9a-z]{32})$


Another possible improvement is adding ^
at the start. This will make sure that line that does not begin with http/https/ftp will not match.
Regex: ^((http[s]?|ftp):\/){1}?\/?([^:\/\s]+)((\/\w+)*\/)([0-9a-z]{32})$
Will not match: test.com/directory1/directory2/67a58dc9165ti206461d34fe1783a7e1
For trying your regex, you can use online tool regex101.com. It explains what your regex means in right panel. For example, mine was explained as such

