- AuthorPosts
- September 11, 2022 at 5:13 am #28352spirosParticipant
In Notepad++
Using as text: ABCDAnd running:
Find: (?:(A)|(B)|(C)|(D))
Replace: (?{1}E:(?{2}F:(?{3}G:(?{4}H:))))The replacement result is: EFGH
However, with Emeditor it is
E)))(?{2}F:(?{3}G:(?{4}H:)))(?{2}F:(?{3}G:(?{4}H:)))(?{2}F:(?{3}G:(?{4}H:)))Is there some difference in replace syntax that is needed or is it not supported?
September 12, 2022 at 11:41 am #28353Yutaka EmuraKeymasterI am not familiar with Notepad++ replacement expressions, but you can learn EmEditor replacement expressions at:
https://www.emeditor.org/en/howto_search_replacement_expression_syntax.html
If you read this page, and still have any questions on a particular expression, please let me know.
September 12, 2022 at 1:37 pm #28354spirosParticipantThanks, I know that page. Since EmEditor uses BoostRegex here are the references
https://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html#boost_regex.format.boost_format_syntax.conditionalsAnd from the page you quote:
If sub-expression N was matched, then true_expression is evaluated and sent to output, otherwise false_expression is evaluated and sent to output. For example, (?1foo:bar) will replace each match found with foo if the sub-expression \1 was matched, and with bar otherwise. Alternatively, you can write the expression in this form: (?{1}foo:bar)
But I still cannot figure out the syntax for the replacement as described.
September 12, 2022 at 7:18 pm #28355DavidParticipantFor me, I’d like to use \J mode in Emeditor for conditional replacement. It’s more easier to understand.
For example, orginal data:
1
2
3Search: \d
Replace: \J if(\0==1){“one”;}else if(\0==2){“two”;}else{“three”;}September 13, 2022 at 12:18 am #28356spirosParticipantInteresting! I tried
Search: [A|B|C|D]
Replace: \J if(\0==A){“alpha”;}else if(\0==B){“beta”;}else{“three”;}And I got “A is undefined”
September 14, 2022 at 5:06 am #28357DavidParticipantWould you please try the following:
Search: [A-D]
Replace: \J if(“\0″==”A”){“alpha”;}else if(“\0″==”B”){“beta”;}else{“three”;}September 14, 2022 at 1:55 pm #28358spirosParticipantThanks! That works. But what if I do not want an else statement at the end? Simple omitting it does nothing. For example.
Test text: прика́з, кома́нда, повеле́ние, нака́з, приказа́ние, распоряже́ние
Find: [о́а́е́и́у́ю́ы́я́]
Replace: \J if(“\0″==”о́”){“о”;}else if(“\0″==”а́”){“а”;}else if(“\0″==”е́”){“е”;}else if(“\0″==”и́”){“и”;}else if(“\0″==”у́”){“у”;}else if(“\0″==”ю́”){“ю”;}else if(“\0″==”ы́”){“ы”;}else if(“\0″==”я́”){“я”;}Expected result: приказ, команда, повеление, наказ, приказание, распоряжение
September 14, 2022 at 5:59 pm #28360DavidParticipantYour Find& Replace expression doesn’t work at my side yet. If I add else{“Nothing change!”;} at the end:
\J if(“\0″==”о́”){“о”;}else if(“\0″==”а́”){“а”;}else if(“\0″==”е́”){“е”;}else if(“\0″==”и́”){“и”;}else if(“\0″==”у́”){“у”;}else if(“\0″==”ю́”){“ю”;}else if(“\0″==”ы́”){“ы”;}else if(“\0″==”я́”){“я”;}else{“Nothing change!”;}
All found character will be changed to “nothing change!”. I don’t know the reason.We can do it another way. Using batch replace function, you can easily achieve your goals
September 15, 2022 at 1:04 am #28361spirosParticipantThanks! Yes, I know batch replace and use it. However, I want to be able to use a conditional regex one liner instead of multiple find replace (even if used in a macro).
If I add else{“Nothing change!”;} at the end All found character will be changed to “nothing change!”. I don’t know the reason.
Apparently some sort of command should be passed to tell it to do nothing since this is JavaScript, i.e. something like null.
September 15, 2022 at 9:10 am #28362Yutaka EmuraKeymasterEmEditor uses Boost.Regex, but NOT the Boost replacement expression function. EmEditor’s replacement function currently doesn’t support these nested conditional expressions. If this is important, I might consider that in future versions.
September 15, 2022 at 9:16 am #28363spirosParticipantIt is a cool regex feature and is already implemented in Notepad++. Would be great to see it in EmEditor too!
September 16, 2022 at 3:31 am #28365DavidParticipantI find another way and test. It seems works correctly.
Search: ^.+$
Replace: \J “\0″.replace(/о́/g,”о”).replace(/а́/g,”а”).replace(/е́/g,”е”).replace(/и́/g,”и”).replace(/у́/g,”у”).replace(/ю́/g,”ю”).replace(/ы́/g,”ы”).replace(/я́/g,”я”)September 16, 2022 at 4:39 am #28366spirosParticipantYes, it works for me too! But there is no way to define in Find which specific characters to search instead of the whole text?
September 16, 2022 at 4:49 pm #28367Yutaka EmuraKeymasterv21.9.908 includes the support for nested conditional expressions.
September 17, 2022 at 1:54 am #28368spirosParticipantOh, magic! Thank you so much for this.
- AuthorPosts
- You must be logged in to reply to this topic.