Current regex: \/bookingkamaroperasi\/((?:\d{2}-){2}\d{4} (?:\d{2}:\d{2}))\/\d{2}
My goal is to match string: /bookingkamaroperasi/10-10-1999 10:00/60
. The problem is, the regex is too long. Is there a way to simplify it?
CodePudding user response:
- You can switch
\d{2}
into\d\d
, saves 4 characters in total. - Your second non-capturing group does not need to be a group.
- Your first non-capturing group can be expanded to
\d\d-\d\d-
which is shorter than the original.
This gives: \/bookingkamaroperasi\/(\d\d-\d\d-\d{4} \d\d:\d\d)\/\d\d
https://regexr.com/75bq1
Also escaping forward slashes is not always necessary depending on the regex engine you are using.