Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index

At 19:55 07/11/2013 +1300, Steve Edmonds wrote:
On 2013-11-07 18:23, Brian Barker wrote:
At 16:55 07/11/2013 +1300, Steve Edmonds wrote:
I am trying to find and replace some text with regex in calc. Can anyone help with how I make it non-greedy.

I think the answer is that you don't: you must find a way of constructing a suitable expression despite such expressions being greedy.

I tried \([:digit:].*?[:digit:]\) in place of \([:digit:].*[:digit:]\) but both are greedy. When the following (12-34-23) cat (233) is in a selected cell it replaces both instances between ().

By the way, I don't understand your ".*?" - do you perhaps mean either ".*" or ".?" ?

I'm afraid you've fallen into the common trap of attempting to define your problem by quoting only expressions that *don't* work! Which parenthesised string do you want to match? I'm guessing the first. But what exactly are the characteristics of the strings you want to match? And the ones you want not to match?

Is the target string always at the beginning?  Try:

Is the target string always digits-hyphen-digits-hyphen-digits? Try:

Do you want to match the second string instead? Try:

Depending on exactly what you want to match and to avoid matching, you may have to do something different.

Sorry I am not that clear now I read it again. In non-LO regex I would use the following (ignoring the quotes)
\(\d.*\d\) to find "(12-34-23) cat (239)"

You are now saying you want to match the entire string - but I suspect you don't mean that.

... in a string (12-34-23) cat (233) the .* is greedy and gobbles everything between the (1 and 9). the ? after the .*, i.e. .*? would be non-greedy and would match (12-34-23) and (239) without including the cat.

So you actually want to match *both* parenthesised strings but not whatever else there is? Is that no matter what is in the parentheses? This is still not a defined problem.

In LO you use [:digit:] in place of \d.

No: you can now use \d as well.

If the parentheses can contain anything (except parentheses), try:

This will need two finds to find two parenthesised strings, but if you are using Replace All that won't matter.

Brian Barker

To unsubscribe e-mail to:
Posting guidelines + more:
List archive:
All messages sent to this list will be publicly archived and cannot be deleted


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.