RimWorld

RimWorld

Post Office: The Letter Filter
Th3_Fr3d  [developer] 19 May, 2024 @ 5:37am
Regular Expressions Help
This mod allows you to filter (hide/show) letter and messages using regular expressions (regex).
Regex is a powerful tool used to search for and match specific patterns of text. Think of it like a very advanced search function that allows you to find specific words or phrases in a text, even if they're surrounded by other text. It's like creating custom filters for text.

That being said, the notation may not be the most intuitive to understand when just starting out, so feel free to ask for help here. There are also great online resources like regex101.com that can help you create the filter you need.

Quick summary of common tasks:
Volcanic winter
literally matches (hides) the letter with the text "Volcanic winter"

Volcanic winter|Toxic fallout
literally matches the text "Volcanic winter" OR "Toxic fallout" (| means "OR")

.*?[Ww]ork$
matches any text ending in "Work" or "work": . means "any character (of the alphabet)", * means "any number of times", ? means "as little times as possible" following by [Ww] a single character of this list (a capital or lowercase w), following by the literal text "ork". $ means "this must be the end of the text". So the regex .*?[Ww]ork$ would hide all the masterwork / Legendary work letters
Last edited by Th3_Fr3d; 19 May, 2024 @ 5:39am
< >
Showing 1-11 of 11 comments
Th3_Fr3d  [developer] 19 May, 2024 @ 5:44am 
Although in today's day and age you can probably also just ask ChatGPT:
Write me a regex in .NET syntax that does the following: ...
be sure to replace "hides the letter xyz" with "matches the text xyz" and "shows the letter xyz" with "does not match the text xyz". Otherwise ChatGPT will likely have no idea what you're talking about (:
Xylem 25 May, 2024 @ 1:54am 
Hey thanks for the guide, and thanks for the mod! I'm trying to block all messages containing certain keywords. Regex101 suggested the following syntax to me:

^.*(apparel|regenerate|impossible).*$

This should block all letters and messages containing "apparel", "regenerate", or "impossible" anywhere within them. But it doesn't seem to be working. I still get these errors and I'm not sure why... Can you tell what I'm doing wrong?
Th3_Fr3d  [developer] 26 May, 2024 @ 10:27am 
@francoquesada
But it doesn't seem to be working. I still get these errors and I'm not sure why...
What exactly is happening that you don't want to happen, or what is not happening that you want to happen? :D Which errors are you referring to?

Your regex *should* basically be correct. Making the first "any" (*) quantifier lazy (*?) would improve performance a bit, and currently your regex is case-sensitive, so "apparel", "regenerate", or "impossible" would have to be lowercase to be matched correctly (I don't know if they are lowercase in the game), so the following regex might be "better" if you don't care about capitalization:

^.*?([Aa]pparel|[Rr]egenerate|[Ii]mpossible).*$

But I'm not sure what errors you are referring to?
I want to hide "A group of visitors from ..... are visiting ...."
what if I wanted to add another kind of letter (use of , )?
Th3_Fr3d  [developer] 2 Jun, 2024 @ 5:28am 
@Sigourney Weaver in Alien4 You could do something along the lines of
(^[A|a] group of visitors from.*?are visiting.*)|(^.*?deteriorated.*)
which would hide the visitor notifications, and some other one (in this case I used the "deterioated" notification as an example).

You can play around with this example here and add your actual other kind of letter and see if it will work: https://regex101.com/r/1NC6JS/1
LKK254 11 Jun, 2024 @ 2:31pm 
How would i go about combining .*?[Ww]ork$ with hiding ground-penetrating scan messages? Would appreciate the help! Thank you!
Th3_Fr3d  [developer] 12 Jun, 2024 @ 6:59am 
@LKK254 you could probably just do something like this:
(^.*?[Ww]ork$)|(the ground-penetrating scan messages)
where you'd replace
the ground-penetrating scan messages
with something that matches the actual ground-penetrating scan messages (I don't remember what these messages say exactly)

I'm actually not sure if the actual ground-penetrating scan messages are *letters* (the things that pop up to the right) or *messages* (in the top left of the screen). If they are *messages* then there's a dedicated input field for that regex, so you wouldn't have to combine it with the Masterwork/Legendary work regex (for messages)
Last edited by Th3_Fr3d; 12 Jun, 2024 @ 7:01am
LKK254 12 Jun, 2024 @ 7:16am 
They are letters that pop up to the right. The title is something like "Scanned underground: Uranium" and the message itself says "Tammy has found a lump of buried uranium using the ground-penetrating scanner!"

Would (^.*?[Ww]ork$)|(lump) work then?
LKK254 12 Jun, 2024 @ 7:27am 
I think i got it to work with (^.*?[Ww]ork$)|(Scanned) but im not certain if it will block other important messages as well.
Th3_Fr3d  [developer] 12 Jun, 2024 @ 3:09pm 
Ah, okay gotcha. The regex currently only applies to letter titles, not to descriptions that show up when you open the letter.
If you want to go the absolute safe route try something like
(([Ll]egendary |[Mm]aster)[Ww]ork)|(Scanned underground:.*)
This should only match the "Legendary work/Masterwork/Scanned underground: <whatever>" letters, so you don't run the risk of inadvertently blocking an important letter ending in "-work" (I don't know if there are any lol) or other letters containing the word "Scanned"
Last edited by Th3_Fr3d; 12 Jun, 2024 @ 3:11pm
Th3_Fr3d  [developer] 12 Jun, 2024 @ 3:15pm 
I'd love to be able to just display a list of all the different letters with enable/disable check-boxes, so that regex wouldn't be needed at all, but afaik there aren't any ways to uniquely identify these letters in the code. And I don't want to manually make a list of all the letter titles, because that
1. wouldn't work with letters added by mods and
2. would depend on the language settings
3. would be a pain to update every time something in the game changes

So perhaps I'll come up with something better in the future, but for now it's regex (:
Last edited by Th3_Fr3d; 12 Jun, 2024 @ 3:16pm
< >
Showing 1-11 of 11 comments
Per page: 1530 50