diff --git a/datumaro/plugins/transforms.py b/datumaro/plugins/transforms.py index b09d372ef9..539a32eca2 100644 --- a/datumaro/plugins/transforms.py +++ b/datumaro/plugins/transforms.py @@ -501,25 +501,26 @@ class Rename(ItemTransform, CliPlugin): the pattern and replacement parts. Replacement part can also contain `str.format` replacement fields with the `item` (of type `DatasetItem`) object available.|n + Please use doulbe quotes to represent regex.|n |n Examples:|n |s|s- Replace 'pattern' with 'replacement':|n .. code-block:: - |s|s|s|srename -e '|pattern|replacement|'|n + |s|s|s|srename -e "|pattern|replacement|"|n |n |s|s- Remove 'frame_' from item ids:|n .. code-block:: - |s|s|s|srename -e '|^frame_||'|n + |s|s|s|srename -e "|^frame_||"|n |n |s|s- Rename by regex:|n .. code-block:: - |s|s|s|srename -e '|frame_(\d+)_extra|{item.subset}_id_\1|' + |s|s|s|srename -e "|frame_(\d+)_extra|{item.subset}_id_\1|" """ @classmethod diff --git a/site/content/en/docs/user-manual/command-reference/transform.md b/site/content/en/docs/user-manual/command-reference/transform.md index 5c1113a2a0..a2e55b1170 100644 --- a/site/content/en/docs/user-manual/command-reference/transform.md +++ b/site/content/en/docs/user-manual/command-reference/transform.md @@ -74,10 +74,13 @@ datum transform -t random_split --overwrite path/to/dataset:voc ``` - Rename images in a project data source by a regex from `frame_XXX` to `XXX`: + + **NOTE:** Please use double quotes (`"`) for regex representation. Check [Reason to use double quotes](https://stackoverflow.com/questions/51080215/differences-between-single-and-double-quotes-in-cmd). + ``` bash datum create <...> datum import <...> -n source-1 -datum transform -t rename source-1 -- -e '|^frame_||' +datum transform -t rename source-1 -- -e "|^frame_||" ``` @@ -152,22 +155,22 @@ Optional arguments: Examples: Replace 'pattern' with 'replacement': ```bash -datum transform -t rename -- -e '|pattern|replacement|' +datum transform -t rename -- -e "|pattern|replacement|" ``` Remove the `frame_` prefix from item ids: ```bash -datum transform -t rename -- -e '|^frame_|\1|' +datum transform -t rename -- -e "|^frame_|\1|" ``` Collect images from subdirectories into the base image directory using regex: ```bash -datum transform -t rename -- -e '|^((.+[/\\])*)?(.+)$|\2|' +datum transform -t rename -- -e "|^((.+[/\\])*)?(.+)$|\2|" ``` Add subset prefix to images: ```bash -datum transform -t rename -- -e '|(.*)|{item.subset}_\1|' +datum transform -t rename -- -e "|(.*)|{item.subset}_\1|" ```