RegEx Rename fail in 4.3

Discussion & Support for xplorer² professional

Moderators: fgagnon, nikos, Site Mods

longfellow
Silver Member
Silver Member
Posts: 231
Joined: 2004 Jun 16, 15:09

RegEx Rename fail in 4.3

Post by longfellow » 2019 Nov 01, 16:11

The arrival of RegEx for Mass Rename is most welcome, but alas! my first test out of the box was a fail. I tried renaming camelCase to snake_case, and vice versa. Here's what happened:

filename = camelCaseToSnakeCase.txt
regexp = (.+?)([A-Z])
replace with = $1_$2
expected result = camel_Case_To_Snake_Case.txt
result = c_am_el_Ca_se_To_Sn_ak_eC_as_e.txt

The quantifier +? should match unlimited times, until it gets to [A-Z], should it not? Why are letters being grouped in two?

If we add the \L token to get lowercase words, it gets worse!

filename = camelCaseToSnakeCase.txt
regexp = (.+?)([A-Z])
replace with = \L$1_\L$2
expected result = camel_Case_To_Snake_Case.txt
result = _Lc__La_Lm__Le_Ll__LC_La__Ls_Le__LT_Lo__LS_Ln__La_Lk__Le_LC__La_Ls__Le.txt

Is the \L token not supported?

snake_case to camelCase also presents problems:

filename = snake_case_to_camel_case.txt
regexp = (.*?)_([a-zA-Z])
replace with = $1\U$2
expected result = snakeCaseToCamelCase.txt
result = snake_Ucase_Uto_Ucamel_Ucase.txt

Seems the \U token is also a problem.

The RegEx I'm using here is pretty standard - is x2 using its own flavor of RegEx? Am I missing something obvious?

(x2 PRO 4.3.0.0 64-bit running on Win 10 1809)

User avatar
nikos
Site Admin
Site Admin
Posts: 14485
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: RegEx Rename fail in 4.3

Post by nikos » 2019 Nov 02, 06:23

I am not very competent with regular expressions, but the available syntax is explained here:
http://www.regexlab.com/en/deelx/syntax.htm

hajubu
New Member
Posts: 8
Joined: 2016 Aug 25, 06:40

Re: RegEx Rename fail in 4.3

Post by hajubu » 2019 Nov 02, 10:49

Hello @Longfellow, @Nikos

I can confirm the observation of @Longfellow above.

I just tested the Syntax for the "camelCaseToSnakeCase.txt" with the Free-Tool Mtrace.zip (MTracerFree_2.1.msi ->Mtracer.exe)

filename = camelCaseToSnakeCase.txt
regexp = (.+?)([A-Z])
replace with = $1_$2
expected result = camel_Case_To_Snake_Case.txt
result = camel_Case_To_Snake_Case.txt

Therefore my conclusion is : xplorer4.3 seems to have a small problem, which needs to be solved.

P.S. MTracerPro3.zip (MTracerUnicodePro_3.0.msi -> MTracer.exe) is not a Free-Tool, but gives the same 'good' result as Mtracer_2.1)
Both can be found on the Website www.regexlab.com
-------------------------------------------

User avatar
nikos
Site Admin
Site Admin
Posts: 14485
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: RegEx Rename fail in 4.3

Post by nikos » 2019 Nov 02, 12:44

the regexp code is offered by DEELX which is outside my control and understanding. Please check the link above for the supported syntax. Not all regexp engines work the same

hajubu
New Member
Posts: 8
Joined: 2016 Aug 25, 06:40

Re: RegEx Rename fail in 4.3

Post by hajubu » 2019 Nov 02, 14:37

Hello @nikos

DEELX - Regular Expression Engine (v1.2) Research project of RegExLab. i.e. all Tutorial and other stuff refer with all syntax rules which you pointed out.

Therefore take my analysis for the problem above as real.

THE both tools (mtracer) are standalone Tools based on DEELX and helps to debug such situations,

Do you agree ?

hajubu
New Member
Posts: 8
Joined: 2016 Aug 25, 06:40

Re: RegEx Rename fail in 4.3

Post by hajubu » 2019 Nov 02, 15:19

Just for those , interested in that case :
- :wink: Have fun !
-------------------------------------

The referenceS for DEELX Users :: http://www.regexlab.com/

Get Started with Regular Expression :: http://www.regexlab.com/start

DEELX Regular Expression Syntax :: http://www.regexlab.com/en/deelx/syntax.htm

Tutorial-Regular Expression Syntax :: http://www.regexlab.com/en/regref.htm

Reg.Expression Compose and Test Tool :: http://www.regexlab.com/mtracer/

------------------------------------

hajubu
New Member
Posts: 8
Joined: 2016 Aug 25, 06:40

Re: RegEx Rename fail in 4.3

Post by hajubu » 2019 Nov 02, 15:33

:beer:
Here an snapshot of the Mtracer result for the 'camelCaseToSnakeCase.txt' of @longfellow
done with the test Tool found at regexlab.com for DEELX cases.

Image

User avatar
nikos
Site Admin
Site Admin
Posts: 14485
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: RegEx Rename fail in 4.3

Post by nikos » 2019 Nov 02, 16:58

ok I see the problem now is that I defined the regexp as ignoring the case of letters. Changing it to "case sensitive" would work for this example, however, as in windows filenames are not case sensitive, there could be other cases where two files with different capitalizations e.g.

FILE1.txt
file2.txt

wouldn't be covered in one go. I am not sure which glitch is more serious? It is either supporting changing filename case, versus freeform search and replace

hajubu
New Member
Posts: 8
Joined: 2016 Aug 25, 06:40

Re: RegEx Rename fail in 4.3

Post by hajubu » 2019 Nov 02, 19:35

Hello @nikos,

Yes, it might be a hard task - but I do believe the 'free-form' gives you the best solution value.
You may have a look to the different forms of the cases.

Thanks for acknowledging the basic problem and taking the burden to ease our life.
:beer: :idea:
------------------------------------------------------------------------------------------------
Case Styles: Camel, Pascal, Snake, and Kebab Case and its variants
are combining words into a single string for better human reading.

These are the popular ways to combine words to form a single concept.
This convention is often used in variable declaration and/or filenames in many languages

Which is best?
There is no best method of combining words.
The main thing is to be consistent with the convention used, and,
if you’re in a team, to come to an agreement on the convention together

------------------------------------------------------------------------------------------------
Camel Case (camelCase) also known as 'camel caps','medial capitals' [iPhone]
combines words by capitalizing all words following the first word and removing the space
(lang: java , javascript , ....(more) )

Pascal Case (PascalCase) known also as 'upper camel case'
combines words by capitalizing all words (even the first word) and removing the space
(lang: Pascal, Modula, ....(more) )

Snake Case (snake_case, SANKE_CASE, Snake_Case)
combines words by replacing each space with an underscore (_) and,
in the all caps version, all letters are capitalized and,
in the Title version, only the first Letter of each word are Capital(s).
(lang: C, C++, ruby, ....(more) )

Kebab Case (kebab-case)
combines words by replacing each space with a dash (-)
(lang: emacs lisp, ....(more) )

mixed camelCase and snake_case
(lang: python, php, perl, ...(more) )

longfellow
Silver Member
Silver Member
Posts: 231
Joined: 2004 Jun 16, 15:09

Re: RegEx Rename fail in 4.3

Post by longfellow » 2019 Nov 02, 20:40

Hi hajubu! Thanks for checking and confirming this!

Hi Nikos! Thanks for the link to the syntax you're using. This page (http://www.regexlab.com/en/deelx/syntax/bas_esc.htm) suggests that characters can be upper- or lower-cased using quoted characters (beginning with \U or \L, and ending with \E). I played around with this but couldn't get it to work. Perhaps it is, as you have pointed out, that the regexp is set to ignore case.

Really, we have to choose between changing case versus free-form search and replace? We want both! Changing case is often required in renaming files; it's too valuable a feature to give up. As for finding FILE1.txt and file2.txt in searches, it shouldn't be too hard for anyone using RegEx to define both lowercase and uppercase characters in their search terms.

User avatar
nikos
Site Admin
Site Admin
Posts: 14485
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: RegEx Rename fail in 4.3

Post by nikos » 2019 Nov 03, 05:12

ok I will change the regexp to case sensitive mode for the next build

longfellow
Silver Member
Silver Member
Posts: 231
Joined: 2004 Jun 16, 15:09

Re: RegEx Rename fail in 4.3

Post by longfellow » 2019 Nov 03, 22:39

Thank you, sir! I look forward to it :)

longfellow
Silver Member
Silver Member
Posts: 231
Joined: 2004 Jun 16, 15:09

Re: RegEx Rename fail in 4.3

Post by longfellow » 2019 Nov 25, 15:12

Thanks, version 4.3.0.1 fixes some of the regexp problems.

filename = camelCaseToSnakeCase.txt
regexp = (.+?)([A-Z])
replace with = $1_$2
expected result = camel_Case_To_Snake_Case.txt
result = camel_Case_To_Snake_Case.txt

Hurrah, no more "c_am_el_Ca_se_To_Sn_ak_eC_as_e.txt"!

Unfortunately case conversion is still a problem.

filename = camelCaseToSnakeCase.txt
regexp = (.+?)([A-Z])
replace with = $1_\L$2\E
expected result = camel_case_to_snake_case.txt
result = camel__LC_Ease__LT_Eo__LS_Enake__LC_Ease.txt

I'm following the instructions here: <http://www.regexlab.com/en/deelx/syntax/bas_esc.htm>
If begins with \L, ends with \E, it will quote (disable) pattern metacharacters from \L till \E, and all uppercase alphas between them will be turned into lowercase."
You can see that the correct characters for conversion are being selected, they're just not being converted. Not sure why there's an extra underscore before the "L".

Same problem with uppercase:

filename = snake_case_to_camel_case.txt
regexp = (.*?)_([a-zA-Z])
replace with = $1\U$2\E
expected result = snakeCaseToCamelCase.txt
result = snake_Uc_Ease_Ut_Eo_Uc_Eamel_Uc_Ease.txt

The \U and \L tokens work fine elsewhere, I can only speculate that it's some peculiarity of the Deelx engine that they don't work here. Perhaps there is some arcane syntax usage I am missing? Sad, as capitalization/decapitalization is a handy feature in a renamer.

Off topic: The new way of calculating folder sizes with Ctrl+D is a great improvement!

User avatar
nikos
Site Admin
Site Admin
Posts: 14485
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: RegEx Rename fail in 4.3

Post by nikos » 2019 Nov 25, 18:42

can you try your regexp in this tool and see what it's supposed to do?
http://www.regexlab.com/mtracer/

longfellow
Silver Member
Silver Member
Posts: 231
Joined: 2004 Jun 16, 15:09

Re: RegEx Rename fail in 4.3

Post by longfellow » 2019 Nov 27, 16:32

nikos wrote:
2019 Nov 25, 18:42
can you try your regexp in this tool and see what it's supposed to do?
http://www.regexlab.com/mtracer/
I get the same results in MTracer as I do in x2's Mass Renamer. MTracer shows that the regexp is correctly parsing the string, it's just the the \L, \U, \Q and \E tokens seem to have no effect as regards case conversion. Again, I can only speculate this is some peculiarity of the Deelx engine. :shrug:

Post Reply