regular expression modifiers
Describe the feature and the current behavior/state
I often need to search-and-replace with regular expressions across line boundaries. TS's documentation says that the regexp syntax is that of Perl. I've read the links carefully. What I'm needing is the "m" modifier, or "s". But I see no way to add regex modifiers in the TeXstudio replace prompts. I've tried using the "escape characters", with no luck. E.g., search strings like 'xxx$\n'. But without "m" or "s", this isn't going to work.
As far as I can see, this is not possible with TeXstudio, so I usually load my file into another editor, like Geany, for this kind of work.
But am I misunderstanding something in TeXstudio's behaviour or syntax? If not, then could this feature be added?
Who will benefit with this feature?
Me and serious regexp users.
Any Other info
TeXstudio 4.7.0 (git 0.0.0++) Using Qt Version 5.15.3, compiled with Qt 5.15.3 R On linux mint.
I've just seen #1900. Perhaps this issue could be brought back to life? You say firmly that TeXstudio obeys PERL regexp, and that's what users would therefore expect. But TeXstudio doesn't obey PERL regexp in this case.
search won't read \n. Usually I turn off TXS and with xed I made the changes. Then I go back.
txs data structure is per line, hence search works per line, as stated in #1900
Is it something that you would consider upgrading?
I have a similar problem. My solution is using a SCRIPT Macro. @sunderme ,@wujastyk ,@FriendsAtDawn
%SCRIPT
dlg = new UniversalInputDialog(['Regular.*Pattern', 'RegPat'], ['g', 'ReFlag'], ['ReplaceAs', 'ReplaceAs']);
if ( dlg.exec() == 1 ) { editor.setText(editor.text().replace(RegExp(dlg.get(0), dlg.get(1)), dlg.get(2)) )} ;
May this helps.
Thank you, @Lyeebn, this is a good solution. I haven't been able to get it working, but I'll persist. I get a blank prompt box.
My txs runs in this way:
I run txs in Win10. Did you try it? What is your OS?MacOS or Linux. Maybe there is a bug, you can ask sunderme. There are other apis besides UniversalInputDialog, such as dialog. You may refer to the User manual of txs.
By the way, txs Script Macros are executed in javascript.
You need a s flag to allow . stand for \n. Refer to JavaScript Regular_Expressions
Old txs does not support s flag. ( For example, My txs is V2.12.10 which was released in 2018, I don't update it for some reasons, such as discussions in #3385 ), In this case, you need to write [\s\S] instead of ..
I'm using Linux and TeXstudio 4.7.1. Probably the macro language has changed a bit. :-(
Don't be sad. I have plan B.
Seems that you have problem with UniversalInputDialog in Ununtu.
UniversalInputDialog is nothing more than an API for interactions (Passing Regular parameters).
You can write the Regular parameters directly in the script.
%SCRIPT
s = editor.text()
s = s.replace(/put your Re.*?Pattern Here/gs, 'replaceto') ;
s = s.replace(/Str to be replaced/gs, 'You can do many replaces in a script') ;
editor.setText(s) ;
The difference (compare to Plan A) is that, your script is not static.
The benefit is that, Scripts can hold your replace rules for further use.
You can assign a hot key to Edit Macros, for example, I assign Shift + ScrollLock for that.
Thank you! That looks good, though there has to be a way to make a dialogue input work. I'm very grateful! Best wishes, Dominik
You guys knows that s***.