texstudio icon indicating copy to clipboard operation
texstudio copied to clipboard

regular expression modifiers

Open wujastyk opened this issue 2 years ago • 11 comments

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.

wujastyk avatar Nov 27 '23 22:11 wujastyk

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.

wujastyk avatar Nov 27 '23 22:11 wujastyk

search won't read \n. Usually I turn off TXS and with xed I made the changes. Then I go back.

FriendsAtDawn avatar Nov 29 '23 03:11 FriendsAtDawn

txs data structure is per line, hence search works per line, as stated in #1900

sunderme avatar Nov 29 '23 19:11 sunderme

Is it something that you would consider upgrading?

wujastyk avatar Nov 29 '23 21:11 wujastyk

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.

Lyeebn avatar Dec 02 '23 03:12 Lyeebn

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. image

wujastyk avatar Dec 04 '23 01:12 wujastyk

My txs runs in this way: image

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 ..

Lyeebn avatar Dec 04 '23 05:12 Lyeebn

I'm using Linux and TeXstudio 4.7.1. Probably the macro language has changed a bit. :-(

wujastyk avatar Dec 04 '23 23:12 wujastyk

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.

Lyeebn avatar Dec 05 '23 01:12 Lyeebn

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

wujastyk avatar Dec 05 '23 01:12 wujastyk

You guys knows that s***.

FriendsAtDawn avatar Dec 06 '23 16:12 FriendsAtDawn