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



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:
\([:digit:]+-[:digit:]+-[:digit:]+\)
or:
\(\d+-\d+-\d+\)

Do you want to match the second string instead? Try:
\([:digit:]+\)
or:
\(\d+\)

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

I trust this helps.

Brian Barker
Thanks for the replies.
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)" 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-gready and would match (12-34-23) and (239) without including the cat. In LO you use [:digit:] in place of \d.

Urmas, if you have "(12-34-23) cat (239)" in a cell in calc and search for \([:digit:].*?[:digit:]\) and replace with ww are you saying you get "ww cat ww" in the cell, ignoring "", i.e. 2 substitutions.
Steve

--
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Context


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.