I'm looking for a regex expression that will capture a file name that does not have an extension and give me that name in a backreference so I can add an extension. So if someone puts in xyz I can replace it with xyz.html. xyz.php or xyz.html should not be captured.
Thanks
Assuming the extensions are up to 4 chars in length (so filenames like mr.smith
aren't considered as having an extension, but mr.smith.doc
and mr.smith.html
are considered as having extensions):
^.*[^.]{5}$
No need to capture a group, as the whole expression is what you want - ie group 0.
Use following regular expression:
^([^.]+)$
meaning filename that only consist of non-dot characters.
UPDATE
added paren for capturing group.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With