How to write a regular expression that references \1 followed by a 0
In regular expressions, if you want to reference the capturing group \1 followed by a number 0, you need to pay special attention to the syntax, because \10 may be interpreted as a reference to the 10th capturing group, rather than \1 followed by 0
I test: \1(0) , (\1)0 and \10 , none of these is correct, so what is right?
I test: \1(0) , (\1)0 and \10 , none of these is correct, so what is right?
Reply to #1:
Hi,
What you want to achieve is something I hope I understand. If you want to add a zero 'immediately' after group 1, you need to use this string: ${1}0
Otherwise, you can use a separator such as an underscore, space or dash. \1_0, \1 0 or \1-0.
Hi,
What you want to achieve is something I hope I understand. If you want to add a zero 'immediately' after group 1, you need to use this string: ${1}0
Otherwise, you can use a separator such as an underscore, space or dash. \1_0, \1 0 or \1-0.
Reply to #2:
Hi folks,
You can use named capture groups. As Styb said, ${1}0 works just fine--and in fact technically I guess it is a named group--but for more complicated expressions named groups might be a better alternative, especially if you have more than 10 capture groups/backreferences in an expression. And even more especially if you can't use the (?x) "free-spacing" mode to separate your groups with spaces for readability. [Later versions of ARen, possibly all v4.x versions allow (?x) - I haven't investigated]
NOTE: I don't think named groups are working in the current version(s) of ARen except 4.12 and 4.13, so you might need to download/use the portable version of one of those for now, until that's fixed. I've only tested on my system (and it's kind of weird) so don't quote me. :)
Best,
DF
Hi folks,
You can use named capture groups. As Styb said, ${1}0 works just fine--and in fact technically I guess it is a named group--but for more complicated expressions named groups might be a better alternative, especially if you have more than 10 capture groups/backreferences in an expression. And even more especially if you can't use the (?x) "free-spacing" mode to separate your groups with spaces for readability. [Later versions of ARen, possibly all v4.x versions allow (?x) - I haven't investigated]
NOTE: I don't think named groups are working in the current version(s) of ARen except 4.12 and 4.13, so you might need to download/use the portable version of one of those for now, until that's fixed. I've only tested on my system (and it's kind of weird) so don't quote me. :)
Best,
DF
Reply to #3:
Many languages don't support "free-spacing" mode in their regex. JavaScript is one such language.
When testing with regex101.com, or similar, be sure that the ECMAScript (JavaScript) flavor is selected. ;P
Many languages don't support "free-spacing" mode in their regex. JavaScript is one such language.
When testing with regex101.com, or similar, be sure that the ECMAScript (JavaScript) flavor is selected. ;P
Reply to #4:
Good point Randy. I'm used to ARen and JGSoft, which do, and js, which doesn't; which is why I said >if< you can't use the (?x) "free-spacing" mode. I tend to gloss over such distinctions. And I assumed ARen v4.x *non-script* regex methods, and as we all know one should never assume. My bad(s)! : ) Thanks!
Best,
DF
Good point Randy. I'm used to ARen and JGSoft, which do, and js, which doesn't; which is why I said >if< you can't use the (?x) "free-spacing" mode. I tend to gloss over such distinctions. And I assumed ARen v4.x *non-script* regex methods, and as we all know one should never assume. My bad(s)! : ) Thanks!
Best,
DF
Reply to #5:
¡Holy Carp! Aren does support free spacing mode!
My apologies.
I'd thought that it would just use JS for regex. My bad.
And https://www.advancedrenamer.com/user_guide/v4/regular_expres ions (sic, the URL is misspelled at the moment) even says that it "uses a regular expression engine ***similar*** to PCRE". (emphasis added).
That changes things and possibly explains a few WTF moments I've seen with Aren.
Thanks for the info.
Best,
RW
¡Holy Carp! Aren does support free spacing mode!
My apologies.
I'd thought that it would just use JS for regex. My bad.
And https://www.advancedrenamer.com/user_guide/v4/regular_expres ions (sic, the URL is misspelled at the moment) even says that it "uses a regular expression engine ***similar*** to PCRE". (emphasis added).
That changes things and possibly explains a few WTF moments I've seen with Aren.
Thanks for the info.
Best,
RW
Reply to #6:
FWIW, lookaround is different between ARen regex and ARen js as well. I can't remember what it is, but I noticed it when ARen regex added lookbehind (I think), a few versions ago.
BTW, I think you misspelled carp... ;)
FWIW, lookaround is different between ARen regex and ARen js as well. I can't remember what it is, but I noticed it when ARen regex added lookbehind (I think), a few versions ago.
BTW, I think you misspelled carp... ;)
Reply to #7:
You've a filthy mind. Whereas I'm merely blasphemous. 0:-)
You've a filthy mind. Whereas I'm merely blasphemous. 0:-)
Reply to #2:
Thanks for your help. sorry for my English is bad and what I mean is just "add a zero 'immediately' after group 1". I test your advice and it worked! Thanks again!
Thanks for your help. sorry for my English is bad and what I mean is just "add a zero 'immediately' after group 1". I test your advice and it worked! Thanks again!
Reply to #9:
Don't worry, because even for me, English is not my first language.
Regards
Don't worry, because even for me, English is not my first language.
Regards
Reply to #9:
...and I promise you, no matter how good or bad your English may be, it is *perfect* compared to my understanding and use of [insert your native language here].
: )
And by the way, you got your point across exactly.
...and I promise you, no matter how good or bad your English may be, it is *perfect* compared to my understanding and use of [insert your native language here].
: )
And by the way, you got your point across exactly.