Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search and Replace with regular expression capture group #233

Closed
binarybeacon opened this issue Jun 18, 2021 · 2 comments · Fixed by #882
Closed

Search and Replace with regular expression capture group #233

binarybeacon opened this issue Jun 18, 2021 · 2 comments · Fixed by #882
Assignees
Labels
feature-request New feature or request released Available in a released installer

Comments

@binarybeacon
Copy link

Is your feature request related to a problem? Please describe.
I have a need to search text in OneNote using a regular expression, but use part of the match in the replacement. For example, if the text in OneNote is "[12:00 PM]", I can use a regular expression to ensure that I'm getting the "[" at the beginning of the line with the time after using the regular expression "^[((1[0-2]|0?[1-9]):([0-5][0-9]) ?([AaPp][Mm]))]" (minus the quotations). However, the capture group that I have included does not work if I use something like "[1/1/2021 $1]" in the replace field, so instead of replacing the text with "[1/1/2021 12:00 PM]", the text is replaced with the literal "[1/1/2021 $1]".

Describe the solution you'd like
I would like to be able to use a regular expression similar to the one in the description above and have it interpolated in the replace field so I can search the instances, keep the desired portion of the string being searched, and add the additional text to the replacement.

Describe alternatives you've considered
The alternative I'm currently using is to manually change all the instances, which is very slow and inefficient.

Additional context
I got the idea from Notepad++, which has a similar feature. If you're aware of an alternative that could do something similar, I would greatly appreciate it. I am a novice programmer and have looked at the source code, although I was unable to determine if this would be a simple implementation that could be achieved by passing an additional argument or two to the Replace method to indicate using Regex.Replace instead of atom.Replace if the search/replace type is useRegex equals true. I hope it's that easy, although I understand that may not be the case and appreciate any and all consideration/effort you might expend on adding this request. Thank you!

THE FINE PRINT
This is a hobby project that I started for myself. I'm happy to take requests and will promise to consider each one carefully but offer no guarantees that I will ultimately agree to their usefulness or have time to implement any of them. If OneNote offers a "close enough" work-around then I will probably reject the request - you've been warned!

@stevencohn stevencohn added the feature-request New feature or request label Jun 19, 2021
@stevencohn stevencohn self-assigned this Jun 28, 2021
@stevencohn stevencohn added the developing Accepted and development is in progress label Jun 28, 2021
@stevencohn
Copy link
Owner

Taking a look but it's not trivial due to the fact that the OneNote schema is XML with embedded HTML and matched text can span multiple XML elements.

@stevencohn stevencohn removed the developing Accepted and development is in progress label Jul 16, 2021
@stevencohn stevencohn removed their assignment Jul 21, 2021
@stevencohn stevencohn self-assigned this Feb 8, 2023
@stevencohn stevencohn added the developing Accepted and development is in progress label Feb 8, 2023
@stevencohn stevencohn linked a pull request Feb 8, 2023 that will close this issue
@stevencohn stevencohn added next-release Addressed but not yet released and removed developing Accepted and development is in progress labels Feb 8, 2023
@stevencohn stevencohn reopened this Feb 8, 2023
@stevencohn
Copy link
Owner

image

@stevencohn stevencohn added released Available in a released installer and removed next-release Addressed but not yet released labels Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request released Available in a released installer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants