-
I'm attempting substitution of a named capture group in CotEditor but I have been unsuccessful using the various conventions (see below). It would be helpful in my quest if I knew what flavor of Regex CoEditor supports and how to change the flavors if possible. I use the Regex "(?...)" to match desired content, and I am successfully in matching throughout my target plain text document using CoEditor as my editor. Usually, of course, when I violate Regex conventions, CotEditor shows me by failing to apply its color coding. This does not happen. So I believe I've complied with the "flavors" requirement. However, when attempting to substitute with "?{Name}", I end up substituting matched content with the literal text, not the content I expected to be captured and bound with the name I declared. Not only would knowing the CotEditor default and supporting flavors help me in researching solutions, it just seems to be something I should know for reference. I'm using a light-weight, web-based diagnostic/inspection tool (Regex 101) to develop my Regex away from CotEditor and typically use its PCRE2 (PHP >=7.3) flavor selection to do so. This flavor seems very portable to CotEditor. For this reason, I have intuited that CoTEdtior supports it. Regex 101 also support PCRE2 <7.3, ECMA (JavaScript), Python, Golang, and Java 8 flavors. I'd go to any of those conventions if I new I could port the regex developed in Regex101 to CorEditor. I supposed I could go to another editor, but I like the light-weight nature of CotEditor and I've built up some familiarity with its use. Can anyone help? Again, at the least, I'm just looking for the flavor. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Hi, thank you for the feedback. The short answer is: CotEditor uses ICU flavored syntax since NSRegularExpression, which CotEditor relies on, is based on. As for the named capture, therefore, it must be captured with |
Beta Was this translation helpful? Give feedback.
-
Thanks for the response. The replacement doesn't work for me either.
Alas.
Brian J. Coady
1454 Monroe St. NW
Washington, DC 20010
(202) 644-3610
… On Jul 31, 2021, at 21:53, 1024jp ***@***.***> wrote:
Hi, thank you for the feedback.
The short answer is: CotEditor uses ICU flavored syntax since NSRegularExpression, which CotEditor relies on, is based on.
ref. https://developer.apple.com/documentation/foundation/nsregularexpression <https://developer.apple.com/documentation/foundation/nsregularexpression>
As for the named capture, therefore, it must be captured with (?<name>foo) and replaced with ${name}, however, in fact, the replacement part seems not to work, although named capture itself works.
I'll look into it later.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#1199 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AVBJAXWEKUGTAVNKVZK4B33T2SSK3ANCNFSM5BKHOO3Q>.
|
Beta Was this translation helpful? Give feedback.
-
Sorry for my late reply. I studied this phenomenon the last week and found NSRegularExpression, the API by Apple which CotEditor relies on, does not support the named capture group for replacement, though it's not explicitly documented. Meanwhile, you can use the named capture in the find string. For instance, Thus, regrettably to say this is in the spec. We need to wait for Apple to implement it for the regex replacement. FYI, the named capture group for the find string itself has first been implemented a few years ago on macOS 10.13. So, it can be changed in the future. PS. The CotEditor project is done in my spare time and on a voluntary basis. So I can work only when I have time. Therefore, please do not expect a commercial product quality response every time. I was really busy in the last months (this is also the reason why I recently slowed down the release pace). |
Beta Was this translation helpful? Give feedback.
-
You've answered my question.
When I say that the syntax highlight didn't work, I believed that I had surpassed the limit. This helps out a whole lot.
Thank You!
Brian J. Coady
1454 Monroe St. NW
Washington, DC 20010
(202) 644-3610
… On Aug 15, 2021, at 22:47, 1024jp ***@***.***> wrote:
I answer your question in #1200 <#1200> here to gather the related information.
Can you confirm whether there is a limit of using the numerical substitution reference ($n) with numbers in the range of 1..9?
What kind of limitation do you expect? As for CotEditor, I suppose the most of limitations are made either by ICU or Apple (namely NSRegularExpression). Therefore, please check those documentations first. If there is any inconsistency between them and CotEditor's implementation, of course, feel free to ask if it is a bug or something.
At least, I confirm you can use a two-digit number for a symbol (Well, the syntax highlight is not correct. I need to fix it).
<https://user-images.githubusercontent.com/1165044/129504799-395ba8e6-d1d2-4c81-8511-9a49971b2069.png>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#1199 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AVBJAXTWPRLRZWXL4GZJYOTT5B33DANCNFSM5BKHOO3Q>.
Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>.
|
Beta Was this translation helpful? Give feedback.
Hi, thank you for the feedback.
The short answer is: CotEditor uses ICU flavored syntax since NSRegularExpression, which CotEditor relies on, is based on.
ref. https://developer.apple.com/documentation/foundation/nsregularexpression
As for the named capture, therefore, it must be captured with
(?<name>foo)
and replaced with${name}
. However, in fact, the replacement part seems not to work, although named capture itself works.I'll look into it later.