Support for \n and \1 in regular expressions
Are you missing a feature? Request its implementation here.
Support for \n and \1 in regular expressions
Currently when you use regular expressions in find/replace, you have to insert newline using Cmd + Enter or using the context menu. More or less all other regular expression languages accept newline as '\n'. Could this be added in a future release?
Also, as a personal preference, I'd like to use '\1' instead of '$1' for back references. If you try to use for example '\1' in the replacement text, the result is just '1'. Does this mean '\' + number is not used for anything in the regexp syntax and could be made a back reference construct?
Also, as a personal preference, I'd like to use '\1' instead of '$1' for back references. If you try to use for example '\1' in the replacement text, the result is just '1'. Does this mean '\' + number is not used for anything in the regexp syntax and could be made a back reference construct?
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Support for \n and \1 in regular expressions
Post by sorin_ristache »
I am sorry, you do not need Cmd + Enter in the Find/Replace dialog. \n is accepted as regular expression that matches a newline character if you select the Regular expression checkbox.jelovirt wrote:Currently when you use regular expressions in find/replace, you have to insert newline using Cmd + Enter or using the context menu.
It means only that \1 does not have special meaning in a regular expression. The syntax of the regular expressions accepted in the Find/Replace dialog is the syntax of Perl 5 regular expressions which I think is kind of standard syntax for regular expressions. I do not know about any regexp language that specifies the substring of the first regexp group with \1 instead of $1. I think we should keep the standard regexp syntax that the users know from other regexp languages instead of inventing our own regexp language.jelovirt wrote:Also, as a personal preference, I'd like to use '\1' instead of '$1' for back references. If you try to use for example '\1' in the replacement text, the result is just '1'. Does this mean '\' + number is not used for anything in the regexp syntax and could be made a back reference construct?
Regards,
Sorin
Re: Support for \n and \1 in regular expressions
Yes, but only in find. If you try to use it in replace, e.g. in equivalet to Perl 's/, /\n/' for input 'foo, bar', you will get 'foonbar'.sorin wrote: I am sorry, you do not need Cmd + Enter in the Find/Replace dialog. \n is accepted as regular expression that matches a newline character if you select the Regular expression checkbox.
I totally agree. I just did a quick test and Perl 5 seems to support both '\1' and '$1'. Hadn't noticed that before. However, e.g. POSIX, Python, Ruby, and Java regexp use '\1'.sorin wrote: It means only that \1 does not have special meaning in a regular expression. The syntax of the regular expressions accepted in the Find/Replace dialog is the syntax of Perl 5 regular expressions which I think is kind of standard syntax for regular expressions. I do not know about any regexp language that specifies the substring of the first regexp group with \1 instead of $1. I think we should keep the standard regexp syntax that the users know from other regexp languages instead of inventing our own regexp language.
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Support for \n and \1 in regular expressions
Post by sorin_ristache »
Yes, in the Replace field \n is not supported as the tooltip of that field specifies. We will consider allowing it in the Replace field too.jelovirt wrote:Yes, but only in find. If you try to use it in replace, e.g. in equivalet to Perl 's/, /\n/' for input 'foo, bar', you will get 'foonbar'.
I am sorry, Java regexp does not allow \1 instead of $1 as the first match group in the replace expression. I tested it with a small Java program. The Javadoc says:jelovirt wrote:I just did a quick test and Perl 5 seems to support both '\1' and '$1'. Hadn't noticed that before. However, e.g. POSIX, Python, Ruby, and Java regexp use '\1'.
Regards,Notable differences from Perl:
* In Perl, \1 through \9 are always interpreted as back references
Sorin
Re: Support for \n and \1 in regular expressions
My bad, I confused backreferences with group references. But in case, Perl does support '\1' and Python only uses it. So, if \n is not currently used for anything, then you could add it without breaking compatibility.sorin wrote:I am sorry, Java regexp does not allow \1 instead of $1 as the first match group in the replace expression.
Re: Support for \n and \1 in regular expressions
Have you any plans on adding support for \n and \t in the search replace in the future releases?
Re: Support for \n and \1 in regular expressions
We have added support for replacing \n, \t and \0...\9. It will be available in the next minor version, 10.3.
Regards,
Radu
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service