#How to regex match on newline?

8 messages · Page 1 of 1 (latest)

meager finch
#

Hello! I am trying to write a show rule which makes all words all in uppercase alone on a line green. The regex "^[A-Z]+$", which I am currently using is not completely working as can be seen in the picture. I have tried using "^[A-Z]+\n$" without success, as none of the words became green.

#show regex("^[A-Z]+$"): set text(green)

WORD // should match and does

a WORD // shouldn't match and doesn't

a  WORD // shouldn't match but does

WORDS // should match and does
in sentence // shouldn't match and doesn't

WORDS in sentence // shouldn't match and doesn't

words IN sentence // shouldn't match and doesn't

words  IN  sentence // shouldn't match but does```

I'm guessing it has something to do with how typst handles linebreaks, which leaves me a bit worried that the problem is deeper than a skill issue with regex on my part. As can be seen in the picture the regex `"^[A-Z]+$"` matches when there are more than 1 spaces between two words, which I also cannot explain why it happens but to my understanding should not happen as the `^` and `$` signs should limit the matching to one line each.

Thankful for all help.
terse kraken
#

it's a limitation with the way that content is parsed into child nodes, see the difference in the fields that these two contents produce

#

?r

#[words IN sentence].fields()

#[words  IN  sentence].fields()
terse kraken
#

the regex matches the IN in the second one because as far as the show rule knows, there is a content node that contains only uppercase letters

#

it doesn't look forward or back to the neighboring child nodes in the rest of the content

meager finch
terse kraken
#

I can't think of anything off the top of my head but maybe someone else will have an idea