I have created a simple Menu which I want to use to display a hint to the user. In the menu, I add a Button.
(if I add a Text directly, its text color turns gray, so this is a workaround. The button doesn't do anything, though).
Menu {
Button { } label: {
Text("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.")
}
} label: {
Image(systemName: "questionmark.circle.fill")
}
This results in the following:
As you can see, the text is cut-off after two lines. If I move the button outside the menu, it properly shows three lines of text. Also, if I replace the Button with just Text, I get the same issue. Same goes for using Label instead of Text inside the button.
I have already tried modifiers like .fixedSize(horizontal: false, vertical: true), or .lineLimit(nil) without any luck.
Does anyone know how I can work around this height limitation?
Related
I'm trying to extract some text from a column on a CSV file. Here is an example:
"Lorem ipsum dolor sit amet (2015), consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua (2000)."
I wanna get a new column with "amet (2015)" and "aliqua (2000)". This expression gives me the (2015) and (2000): value.find(/(.*?)/)
But how can I also get the word before the parentheses?
here is the regex your are looking for /\w* \([^\)]*\)/gm.
I have used both AWS SSM on the web UI and also installing the SSM plugin on my terminal (Using MacOS Monterrey Terminal) and on both I have the same odd behaviour when pasting multi-line text:
My source text:
"Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
Ut enim ad minim veniam"
When pasting it in a file inside my Amazon Linux 2 instance connected through SSM (both Web and CLI plugin)
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam"
I expect it to paste the source text exactly including all the line break characters, like it does when one connects using plain SSH.
It def seems to be omitting the line break characters \n or carry return character. Not sure how to proceed.
Which editor are you using? I noticed the same weird behavior with nano but fortunately, if you use vi, your formatting is respected in both the AWS SSM web UI and via the SSM plugin.
Below is my test string:
Object: TLE-234DSDSDS324-234SDF324ER
Page location: SDEWRSD3242SD-234/324/234 (1)
org-chart Lorem ipsum dolor consectetur adipiscing # Colorado
234DSDSDS324-32-4/2/7-page2 (2) loc log Apr 18 21:42:49 2017 1
Page information: 3.32.232.212.23, Error: fatal, Technique: color
Comments: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Validation status: Lorem ipsums dolors sits amets, consectetur adipiscing elit
Positive control-export: Validated
Page location: SDEWRSD3242SD-SDF/234/324 (5)
org-chart Lorem ipsum dolor consectetur adipiscin # Arizona
234DSDSDS324-23-11/1/0-page1 (1) loc log Apr 18 21:42:49 2017 1
Page information: 3.32.232.212.23, Error: log, Technique: color
Comments: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Validation status: Lorem ipsums dolors sits amets, consectetur adipiscing elit
Positive control-export: Validated
I need to capture strings after the "Page location: ", "Object: " and "Comments: "
For example:
Object: TLE-234DSDSDS324-234SDF324ER - Group 1
Page location: SDEWRSD3242SD-234/324/234 (1) - Group 2
Page location: SDEWRSD3242SD-SDF/234/324 (5) - Group 3
Comments: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - Group 4
Comments: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - Group 5
Here is my regex URL.
I am able to capture the strings but the regex won't capture if any one of the string is repeated.
(See comments below the question for the problem description.)
The data is in a multi-line string, with multiple sections starting with Object:. Within each there are multiple lines starting with phrases Page location: and Comments:. The rest of the line for all these need be captured, and all organized by Objects.
Instead of attempting a tortured multi-line "single" regex, break the string into lines and process section by section. This way the problem becomes a very simple one.
The results are stored in an array of hashrefs; each has for keys the shown phrases. Since they can appear more than once per section their values are arrayrefs (with what follows them on the line).
use warnings;
use strict;
use feature 'say';
my $input_string = '...';
my #lines = split /\n/, $input_string;
my $patt = qr/Object|Page location|Comments/;
my #sections;
for (#lines)
{
next if not /^\s*($patt):\s*(.*)/;
push #sections, {} if $1 eq 'Object';
push #{ $sections[-1]->{$1} }, $2;
}
foreach my $sec (#sections) {
foreach my $key (sort keys %$sec) {
say "$key:";
say "\t$_" for #{$sec->{$key}};
}
}
With the input string copied (suppressed above for brevity), the output is
Comments:
Lorem ipsum dolor sit amet, [...]
Lorem ipsum dolor sit amet, [...]
Page location:
SDEWRSD3242SD-234/324/234 (1)
SDEWRSD3242SD-SDF/234/324 (5)
Object:
TLE-234DSDSDS324-234SDF324ER
A few comments.
Once the Object line is found we add a new hashref to #sections. Then the match for a pattern is set as a key and the rest of its line added to its arrayref value. This is done for the current (so last) element of #sections.
This adds an empty string if a pattern had nothing following. To disallow add next if not $2;
Note. An easy and common way to print complex data structures is via the core module Data::Dumper. But also see Data::Dump for a much more compact printout.
I have to format 50k lines of chat logs.
The source file is pure text and looks something like this:
13. Mär. 01:32 - Walter:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
13. Mär. 06:15 - Horst:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua.
magna aliquyam erat, sed diam voluptua.
There are only two persons in the whole chat - Walter and Horst.
I need two regular expressions, one that selects all chat text from Walter and one that selects all chat text from Horst.
The regular expression for Walter should select this text from the example:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
The regular expression for Horst should select this text from the example:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua.
magna aliquyam erat, sed diam voluptua.
It's important to me to only select the text lines and not the date / time / person line.
UPDATE
First off, thanks for the fast reply. Unfortunately this doesn't solve my problem.
Chat texts have a varying line of numbers.
And somehow I cannot get a selection with your example.
I tried it here:
http://regexr.com/39m2a
I tried this instead:
Walter:.\n(.)
This selects Walter: and the first line. Is there away NOT to select Walter: ?
(I need this to format an Indesign Document using text formats)
These are actualy 2 questions
How to do a match across newlines (asked in the question title)
How to do a match that discards the date/time/person (asked in
the question body)
I'll answer question 1:
Before doing the match you want to change the line separator/record separator.
This separator is tool dependent (it is not part of the regex language itself). E.g. for awk you can change the RS variable (you can set it to multiple characters, e.g., colon+newline). For GNU grep you can use -z. See longer discussion at
How to find patterns across multiple lines using grep?
Here's my solution:
awk '$5~/Walter:$/{p=1} $5!~/Walter:$/&&$5~/:$/{p=0} p'
or
awk -vname=Walter 'match($5,name":$"){p=1} !match($5,name":$")&&$5~/:$/{p=0} p'
To filter out empty and date lines, pipe through
awk '$5!~":$"&&NF>0'
try it here: http://refiddle.com/1iws
I have modified the regex so could work on you data, but once again your data isn't well structured though it's not possible to write a single regex that would match it correctly
This string is indexed: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
My query is: "Hello world. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Other text."
When I run the query I get no results. How can I get the result if my query has a little "garbage" text in it?
I am using Django, Haystack, and ElasticSearch.
If you use a "match" query with the default operator of "or", then you'll get hits where any of the words match, but hits where lots of the words match will rank above hits where few of the words match.
http://www.elasticsearch.org/guide/reference/query-dsl/match-query.html
But if you mean you only want to match that exact phrase, but allow some additional text on either end, I'm not sure you can do precisely that.
One option, if you can relax the requirement for an exact phrase match, would be to analyse the documents (and the query) using a shingle token filter.
http://www.elasticsearch.org/guide/reference/index-modules/analysis/shingle-tokenfilter.html
Then a match query with "or" operator would operate on pairs, triplets, quads etc. of words (depending on filter configuration). Setting the shingle size to just 2 or 3 would make it unlikely that a document containing many of the same words as the query (by chance) would score highly.
Or you could use a phrase query with slop (see bottom of match query page above).
Both of these approaches would allow insertions as well as prefixes/suffixes though.
Elasticsearch has really powerful More Like This Query that allows you to generate queries based on fragments of text.