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


At 18:42 10/09/2020 +0100, Séamas Ó Brógáin wrote:
Some time ago Brian Barker provided a brilliant formula for finding all text between less-than and greater-than signs, namely
<[^>]*>

I've been trying to adapt it to finding text within brackets [thus], but without success. I know that brackets as such, as distinct from regular expressions, are identified as \[ and \]; so the formula I've come up with is
\[[^>]*\]

Unfortunately there are two things wrong with this: (1) it finds all text until a later closing bracket (seemingly the last one in the same paragraph) but not necessarily the immediately following one, ...

That central greater-than sign also needs to become a close bracket:
\[[^]]*\]

... and (2) the selection includes the brackets themselves, whereas I only want the text that they enclose. Am I attempting the impossible?

Yes and no. I don't see how you can match something that then doesn't include parts of the pattern. (Others may know better.) But there are things you can do:

o If you want to replace what is contained in the brackets but not the brackets themselves, you can reinsert them in the "Replace with" string, as "[something-else]" (no quotes).

o You can mark the brackets and their contents separately - using parentheses - and then use the parts in the replacement. Use
(\[)[^]]*(\])
and then "$1something-else$2" (no quotes) in the replacement. "$1" refers to the first parenthesised part and "$2" to the second - in this case the brackets themselves.

o Another technique would be to match the entire string, including the brackets, do what you want with that, and then perform another Find & Replace to correct the unwanted effect on the brackets. One idea might be to include additional brackets in the replacement, so that the result would be "[[something-else]]". Then it would be a simple task to search for those double brackets and do whatever was required.

It's difficult to be more precise without knowing exactly what you are trying to achieve.

I trust this helps.

Brian Barker


--
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy

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.