Download
Magazine
Develop
Account
Download
Magazine
Develop
Login
Forgot Account/Password
Create Account
Language
Help
Language
Help
×
Login
Login Name
Password
×
Forgot Account/Password
Category:
Software
People
PersonalForge
Magazine
Wiki
Search
OSDN
>
Find Software
>
Text Editors
>
SAKURA Editor
>
Forums
>
一般話題(質疑・要望等)
>
正規表現における小括弧"()"のエスケープが効かない
SAKURA Editor
Description
Project Summary
Developer Dashboard
Web Page
Developers
Image Gallery
List of RSS Feeds
Activity
Statistics
History
Downloads
List of Releases
Stats
Ticket
Ticket List
Milestone List
Type List
Component List
List of frequently used tickets/RSS
Submit New Ticket
Documents
FrontPage
Title index
Recent changes
Communication
Forums
List of Forums
一般話題(質疑・要望等) (403)
マクロ掲示板 (60)
Mailing Lists
list of ML
News
Forums:
一般話題(質疑・要望等)
(Thread #45982)
Return to Thread list
RSS
正規表現における小括弧"()"のエスケープが効かない (2022-06-02 09:44 by
tm
#90148)
Reply
if文と小括弧"("前のスペースを1つに固定する置換マクロを実装したいのですが、正規表現で"("をエスケープすることができません。
実際の構文が以下になります。
Editor.ReplaceAll('if *\(', 'if (')
これを実行すると、'end pattern with unmatched parenthesis'エラーで実行されません。
正規表現自体が合っていそうなことは他サイトで確認できています。
どのような原因が考えられるでしょうか。
Reply to #90148
×
Subject
Body
Reply To Message #90148 > if文と小括弧"("前のスペースを1つに固定する置換マクロを実装したいのですが、正規表現で"("をエスケープすることができません。 > 実際の構文が以下になります。 > Editor.ReplaceAll('if *\(', 'if (') > これを実行すると、'end pattern with unmatched parenthesis'エラーで実行されません。 > 正規表現自体が合っていそうなことは他サイトで確認できています。 > どのような原因が考えられるでしょうか。
You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.)
Login
Nickname
Preview
Post
Cancel
Re: 正規表現における小括弧 (2022-06-02 09:47 by
tm
#90149)
Reply
正しくは
Editor.ReplaceAll('if *\(', 'if \(',6) ;
です。
これでもマクロは動作しません。
Reply to
#90148
Reply to #90149
×
Subject
Body
Reply To Message #90149 > 正しくは > Editor.ReplaceAll('if *\(', 'if \(',6) ; > です。 > これでもマクロは動作しません。
You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.)
Login
Nickname
Preview
Post
Cancel
Re: 正規表現における小括弧 (2022-06-02 18:41 by
berryzplus
#90156)
Reply
サクラエディタの不具合ではなさそうな気がします。
Reply To Message #90149
> 正しくは
> Editor.ReplaceAll('if *\(', 'if \(',6) ;
> です。
> これでもマクロは動作しません。
javascriptで書いた正規表現: 'if *\('
↓
サクラエディタに渡される文字列: 'if *('
javascriptでは
Editor.ReplaceAll('if *\\(', 'if (',6) ;
と書かないと意図した文字列になりません。
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String#escape_notation
Reply to
#90149
Reply to #90156
×
Subject
Body
Reply To Message #90156 > サクラエディタの不具合ではなさそうな気がします。 > > Reply To Message #90149 > > 正しくは > > Editor.ReplaceAll('if *\(', 'if \(',6) ; > > です。 > > これでもマクロは動作しません。 > > javascriptで書いた正規表現: 'if *\(' > ↓ > サクラエディタに渡される文字列: 'if *(' > > javascriptでは > Editor.ReplaceAll('if *\\(', 'if (',6) ; > と書かないと意図した文字列になりません。 > https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String#escape_notation
You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.)
Login
Nickname
Preview
Post
Cancel
Re: 正規表現における小括弧 (2022-06-02 19:10 by
AC
#90157)
Reply
エスケープを二重にします。こうです「Editor.ReplaceAll('if *\\(', 'if (',6) ;」
'if *\\(' と記述された J(ava)Script の文字列リテラルが、最初にスクリプトエンジンによって「if *\(」という内容を持つ文字列として解釈され保持されます。
次に Editor オブジェクトの ReplaceAll メソッドが最初の引数として「if *\(」という内容を持つ文字列を受け取り、そのまま正規表現エンジンに渡し、正規表現エンジンが「if *\(」を解釈します。
解釈する主体が2つあるために、正規表現エンジンのためのエスケープと J(ava)Script のためのエスケープをこの順番で二重に行う必要があります。(エスケープ文字が同じ \ なのはたまたまですね)
それでは
Reply to
#90149
Reply to #90157
×
Subject
Body
Reply To Message #90157 > エスケープを二重にします。こうです「Editor.ReplaceAll('if *\\(', 'if (',6) ;」 > > 'if *\\(' と記述された J(ava)Script の文字列リテラルが、最初にスクリプトエンジンによって「if *\(」という内容を持つ文字列として解釈され保持されます。 > 次に Editor オブジェクトの ReplaceAll メソッドが最初の引数として「if *\(」という内容を持つ文字列を受け取り、そのまま正規表現エンジンに渡し、正規表現エンジンが「if *\(」を解釈します。 > > 解釈する主体が2つあるために、正規表現エンジンのためのエスケープと J(ava)Script のためのエスケープをこの順番で二重に行う必要があります。(エスケープ文字が同じ \ なのはたまたまですね) > > それでは
You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.)
Login
Nickname
Preview
Post
Cancel
Re: 正規表現における小括弧 (2022-06-02 19:11 by
AC
#90158)
Reply
投稿直前にリロードすべきでした。
Reply to
#90157
Reply to #90158
×
Subject
Body
Reply To Message #90158 > 投稿直前にリロードすべきでした。 >
You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.)
Login
Nickname
Preview
Post
Cancel