Recent

Author Topic: Regular expressions in Incremental Search  (Read 310 times)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 412
Regular expressions in Incremental Search
« on: September 15, 2024, 08:52:57 pm »
Is there a way of incorporating a regular expression into an Incremental Search (Cmd/Ctrl E)?

This would really help me do a bit of text wrangling using a keyboard macro.
I've discovered the regular expression I need... ",,([A-Za-z0-9]+(,[A-Za-z0-9]+)+),,", but while it works in a normal find (with Reg Ex enabled), it doesn't seem to work in the Incremental search context.
"It builds... ship it!"

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10296
  • Debugger - SynEdit - and more
    • wiki
Re: Regular expressions in Incremental Search
« Reply #1 on: September 16, 2024, 10:26:22 am »
Well, it would mean to add new code to the IDE. And since ctrl-e does not have a checkbox to toggle, it would mean to add a new key-combo.

Such a feature could be contributed...

Reg expression incr search would have interesting side effects though, as the found pos would jump forward and backward.
Imagine you are starting at line 10, and start searching Foo and that is found at line 20.
No you add to your search pattern Foo?  and that can be found at line 12. So the search needs to go back...



For now you have some other options...

Once you searched (normal) you can repeat that search. But of course only if you havent searched something else...

You can however create a PascalScript macro
https://wiki.lazarus.freepascal.org/Editor_Macros_PascalScript#Functions
And call searchReplaceEx with a hardcoded search pattern. Then you can assign it to a key, and that key will always do the exact search you gave in your post.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10296
  • Debugger - SynEdit - and more
    • wiki
Re: Regular expressions in Incremental Search
« Reply #2 on: September 16, 2024, 10:30:04 am »
Such a feature could be contributed...

Actually, as intriguing as it may be to add it, it may not be a good idea.

It then needs to deal with errors, when a reg ex is incomplete: (a|b
missing the )

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 412
Re: Regular expressions in Incremental Search
« Reply #3 on: September 16, 2024, 05:18:11 pm »
You can however create a PascalScript macro
https://wiki.lazarus.freepascal.org/Editor_Macros_PascalScript#Functions
And call searchReplaceEx with a hardcoded search pattern. Then you can assign it to a key, and that key will always do the exact search you gave in your post.

Being born and raised on Delphi 1 thru 7, I'm just used to the simple macro record and play. I'll have to check out the PascalScript that you mention  :)
"It builds... ship it!"

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 412
Re: Regular expressions in Incremental Search
« Reply #4 on: September 16, 2024, 05:20:54 pm »
Actually, as intriguing as it may be to add it, it may not be a good idea.

It then needs to deal with errors, when a reg ex is incomplete: (a|b
missing the )

Don't worry about it. I was able to solve the problem with the standard search and replace. Besides this PascalScript sounds pretty powerful  :)
"It builds... ship it!"

 

TinyPortal © 2005-2018