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

--replace which regex can be used and how replace with empty string #173

Open
atticus-sullivan opened this issue May 30, 2021 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@atticus-sullivan
Copy link

This is some kind of a follow up from #171 but the question is somewhat more general.

How would one replace a string by an empty string via a replacement file?

Currently, I'm using \\figref\{.*\} but this replaces with a space (which throws some warnings about spaces before punctuation etc.). Just \\figref\{.*\} (no space at the end) didn't work for me as well.

Maybe you could elaborate too on, how the regexes are evaluated.

Is it possible to use perl regex to specify whether * should be greedy or not?

Does Both search and replace can be regular expressions. mean that one can use backreferences in the regexes? If not what does this mean? That one can use a regex as replacement? (As far as I checked, .* is considered as string not as regex in the replacement 'column')

@sylvainhalle
Copy link
Owner

It all happens in thie class: https://github.com/sylvainhalle/textidote/blob/master/Source/Core/src/ca/uqac/lif/textidote/cleaning/ReplacementCleaner.java

The replacement itself occurs in AnnotatedString:

public /*@ non_null @*/ AnnotatedString replace(String regex, String to, Position start)

I wrote this quite some time ago, but as I see in the code, you can use groups (parentheses) in the find pattern and group references (e.g. $1, etc.) in the replacement pattern --although be warned that there does not seem to be any unit test covering this feature!

As to the way to replace a string by nothing (empty string), indeed I don't think it can be done at the moment. Will think of a way of allowing this...

@sylvainhalle sylvainhalle added the enhancement New feature or request label Jun 1, 2021
@sylvainhalle sylvainhalle added this to the v0.9 milestone Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants