Since it doesn't seem like anyone else has done this yet, I'm going to start a thread to document all the practical uses in starmade for regEx that I've discovered. Hopefully this will allow people to use the the new features of display blocks without:
A: Learning regEx.
B: Depending on a player with a logic badge or equivalent knowledge to help them.
This isn't to say that learning regEx is bad, as it's actually a good thing. It's not overly difficult either, I spent 4-5 hours studying the language and already I'm starting to understand most of the concepts. But I can totally agree with people that don't want to take the time to learn a new coding language. It's a fairly old and seldom used language. So seldom used in fact that I've found stack overflow pages with a single response to my googled question saying "regex isn't the best for this."
So to prevent hair pulling and google crusades, here's a frequently updating list of all the practical applications and regex statements I've discovered. I'm sure these aren't nearly optimized, and I will update the different applications as more optimized methods are discovered. I use Regex101 - online regex editor and debugger to test my code in, it's much more useful than testing in starmade because it gives you feedback on what every part of the code does. Still have to test in starmade though because there are quirks that must be overcome.
p.s. each line is a regex statement that needs to be in its own display block. To edit the contents of a display, put a button or activator next to the display you want to use as the modifier, then V the button to the display module you want to modify.
===============================================
IMPORTANT: SPACES ARE HARD TO SEE, USE SEMICOLONS TO SEPARATE FIELDS. WHY IS THIS IMPORTANT? LOOK AT THIS CODE:
PlayerPoints1[300] PlayerPoints2[400] PlayerPoints3[500] PlayerPoints4[700]
huh, spaces, cool.
;PlayerPoints1[300];PlayerPoints2[400];PlayerPoints3[500];PlayerPoints4[700];
woah, semicolons!!!!!!!
I'm explaining this poorly, but take my word for it.. when you work with regex, it REALLY loves to grab whatever it can into it's precious matches. For compatibility reasons, it's better in the long run to use semicolons to replace spaces for different fields. then you can specify between strings and variables.
===============================================
That's all for now, but I'm currently focusing on regex related logic so there's sure to be more soon!
Here's the link to the breadboard demonstration for all the regex I'm working on:
regEx compilation breadboard currently contains:
-binary multiplier (binary adder with slight conversion, god binary multiplication is easy)
-display decimal to logic binary converter. (uses the binary multiplier, can go back to a display block as binary easy, Im just lazy lol. I'll add it later..)
-regex string field seperator (my string parser. seperates :fields: onto separate displays.)
-regex variable extractor/editor/injector. (Used GalactusX's regex heavily as reference)[/URL]
A: Learning regEx.
B: Depending on a player with a logic badge or equivalent knowledge to help them.
This isn't to say that learning regEx is bad, as it's actually a good thing. It's not overly difficult either, I spent 4-5 hours studying the language and already I'm starting to understand most of the concepts. But I can totally agree with people that don't want to take the time to learn a new coding language. It's a fairly old and seldom used language. So seldom used in fact that I've found stack overflow pages with a single response to my googled question saying "regex isn't the best for this."
So to prevent hair pulling and google crusades, here's a frequently updating list of all the practical applications and regex statements I've discovered. I'm sure these aren't nearly optimized, and I will update the different applications as more optimized methods are discovered. I use Regex101 - online regex editor and debugger to test my code in, it's much more useful than testing in starmade because it gives you feedback on what every part of the code does. Still have to test in starmade though because there are quirks that must be overcome.
p.s. each line is a regex statement that needs to be in its own display block. To edit the contents of a display, put a button or activator next to the display you want to use as the modifier, then V the button to the display module you want to modify.
===============================================
IMPORTANT: SPACES ARE HARD TO SEE, USE SEMICOLONS TO SEPARATE FIELDS. WHY IS THIS IMPORTANT? LOOK AT THIS CODE:
PlayerPoints1[300] PlayerPoints2[400] PlayerPoints3[500] PlayerPoints4[700]
huh, spaces, cool.
;PlayerPoints1[300];PlayerPoints2[400];PlayerPoints3[500];PlayerPoints4[700];
woah, semicolons!!!!!!!
I'm explaining this poorly, but take my word for it.. when you work with regex, it REALLY loves to grab whatever it can into it's precious matches. For compatibility reasons, it's better in the long run to use semicolons to replace spaces for different fields. then you can specify between strings and variables.
===============================================
Jaaskinal- "If you're looking to add a command to the beginning of a text, I like to use [replacefirst][with][add] since it has no prerequisite for what characters must be contained in the text.
GalactusX- "Currently the function [REPLACEFIRST] ... [WITH] and [REPLACEALL] ... [WITH] can not replace something, with nothing ... BUT We can tell the regex command to replace anything with an "empty field" using references"
[ Text to replace all numbers "I play StarMade 0.199.429" --> [REPLACEALL][0-9.]()[WITH]$1 --> Result "I play StarMade" ]
The parentheses are the blank field, the $num symbol copies the group with the matching number. The second (1st) match is nothing, so it replaces what is selected (the numbers) with nothing.
GalactusX- "Currently the function [REPLACEFIRST] ... [WITH] and [REPLACEALL] ... [WITH] can not replace something, with nothing ... BUT We can tell the regex command to replace anything with an "empty field" using references"
[ Text to replace all numbers "I play StarMade 0.199.429" --> [REPLACEALL][0-9.]()[WITH]$1 --> Result "I play StarMade" ]
The parentheses are the blank field, the $num symbol copies the group with the matching number. The second (1st) match is nothing, so it replaces what is selected (the numbers) with nothing.
For a long while off and on, I've been trying to create a basic scripting language in starmade, a way to convert sentences into a series of logic commands and have each command activate some logic. To do this, you need two different statements, one to remove the first field (word), and another to remove the last. This example uses : as the word separator, so you can have multiple words in a single field.
EX: :test: of the: string parsing :system:
1st statement: Regex101 - online regex editor and debugger
2nd statement: Regex101 - online regex editor and debugger
I'm sure there is a way to dynamically read each word to a quite extended length, but as of now I only know how to do it statically. for each word you know the sentence will have, you need to run those two bits of code until you have only 1 field left, then store that text. you can do this by making a display shift register.
EX: :test: of the: string parsing :system:
1st statement: Regex101 - online regex editor and debugger
2nd statement: Regex101 - online regex editor and debugger
Code:
removal of first field: (replace number with amount of fields forward you want)
[replaceall]^(:([^:]*:){2})[with]:
removal of last field (2 steps): (replace number with amount of fields back you want)
[replaceall](:([^:]*:){2})$[with]:
This doesn't work properly, I need to find a way to remove the line entirely instead of replacing the line with something else... It's the same as string parsing, but use these two sets of code instead:
1st statement: Regex101 - online regex editor and debugger
2nd statement: Regex101 - online regex editor and debugger
1st statement: Regex101 - online regex editor and debugger
2nd statement: Regex101 - online regex editor and debugger
Code:
to erase the first line:
^(.*\n)
to erase the last line:
(\n.*)$
Very simple to create with any amount of displays. To set one up, just daisy chain a row of buttons or activators, then place a display block adjacent to each button. At the end of the chain, connect the button to the display block of the next button down the line. Continue all the way back to the beginning of the chain. Put some text in the display block at the end of the chain and press the button at the beginning. Thanks to instant pulses, the buttons are activated one after the other down the chain! The second display updates the first, the third display updates the second, and so on.
Snapems' logic counter:
RegEx Logic - Counter
I actually have yet to figure out how this works, so I'll leave the explaining to Snapems
1st statement: Regex101 - online regex editor and debugger
2nd statement: Regex101 - online regex editor and debugger
(these work with any number, mess around on the website a bit and figure out how to substitute the number in the test string with a different number.
1st statement: Regex101 - online regex editor and debugger
2nd statement: Regex101 - online regex editor and debugger
3rd statement: Regex101 - online regex editor and debugger
(doesnt seem to be neccesary)
=========================================
Jaaskinal's hexidecimal counter:
1st statement:Regex101 - online regex editor and debugger
2nd statement:Regex101 - online regex editor and debugger
1st statement:Regex101 - online regex editor and debugger
2nd statement:Regex101 - online regex editor and debugger
---------------------------------------------------------------------------------------
Jaaskinal's binary counter:
1st statement: Regex101 - online regex editor and debugger
2nd statement: Regex101 - online regex editor and debugger
1st statement: Regex101 - online regex editor and debugger
2nd statement: Regex101 - online regex editor and debugger
RegEx Logic - Counter
I actually have yet to figure out how this works, so I'll leave the explaining to Snapems
1st statement: Regex101 - online regex editor and debugger
2nd statement: Regex101 - online regex editor and debugger
(these work with any number, mess around on the website a bit and figure out how to substitute the number in the test string with a different number.
Code:
to count up a number in a display block:
[REPLACEALL]\b([0-9]+)\b[WITH]0$1~01234567890
[REPLACEALL]\b0(?!9*~)|([0-9])(?=9*~[0-9]*?\1([0-9]))|~[0-9]*[WITH]$2
2nd statement: Regex101 - online regex editor and debugger
3rd statement: Regex101 - online regex editor and debugger
(doesnt seem to be neccesary)
Code:
to count down:
[REPLACEALL]\b([0-9]+)\b[WITH]$1~09876543210
[REPLACEALL]\b0|([0-9])(?=0*~[0-9]*?\1([0-9]))|~[0-9]*[WITH]$2
(The third statement removes a potential leading 0 from the beginning instead of leaving it there.)
[REPLACEALL]\b0|([0-9])(?=0*~[0-9]*?\1([0-9]))|~[0-9]*[WITH]$2
Jaaskinal's hexidecimal counter:
1st statement:Regex101 - online regex editor and debugger
2nd statement:Regex101 - online regex editor and debugger
1st statement:Regex101 - online regex editor and debugger
2nd statement:Regex101 - online regex editor and debugger
Code:
To count up:
[REPLACEALL]\b([0-F]+)\b[WITH]0$1~0123456789ABCDEF0
[REPLACEALL]\b0(?!F*~)|([0-F])(?=F*~[0-F]*?\1([0-F]))|~[0-F]*[WITH]$2
To count down:
[REPLACEALL]\b([0-F]+)\b[WITH]0$1~0123456789ABCDEF0
[REPLACEALL]\b0|([0-F])(?=0*~[0-F]*?\1([0-F]))|~[0-F]*[WITH]$2
To count up in odd numbers, but also skip odd beginnings:
[REPLACEALL]\b([0-F]+)\b[WITH]0$1~013579BDF1
[REPLACEALL]\b0(?!F*~)|([0-F])(?=F*~[0-F]*?\1([0-F]))|~[0-F]*[WITH]$2
To count forwards but also backwards at the same time: (i guess)
[REPLACEALL]\b([0-F]+)\b[WITH]0$1~0FEDCBA9876543210
[REPLACEALL]\b0(?!F*~)|([0-F])(?=F*~[0-F]*?\1([0-F]))|~[0-F]*[WITH]$2
Jaaskinal's binary counter:
1st statement: Regex101 - online regex editor and debugger
2nd statement: Regex101 - online regex editor and debugger
1st statement: Regex101 - online regex editor and debugger
2nd statement: Regex101 - online regex editor and debugger
Code:
To count up:
[REPLACEALL]\b([0-1]+)\b[WITH]0$1~010
[REPLACEALL]\b0(?!1*~)|([0-1])(?=1*~[0-1]*?\1([0-1]))|~[0-1]*[WITH]$2
To count down:
[REPLACEALL]\b([0-1]+)\b[WITH]0$1~010
[REPLACEALL]\b0|([0-1])(?=0*~[0-1]*?\1([0-1]))|~[0-1]*[WITH]$2
Here's the link to the breadboard demonstration for all the regex I'm working on:
regEx compilation breadboard currently contains:
-binary multiplier (binary adder with slight conversion, god binary multiplication is easy)
-display decimal to logic binary converter. (uses the binary multiplier, can go back to a display block as binary easy, Im just lazy lol. I'll add it later..)
-regex string field seperator (my string parser. seperates :fields: onto separate displays.)
-regex variable extractor/editor/injector. (Used GalactusX's regex heavily as reference)[/URL]
-Jaaskinal: [REPLACEFIRST](.*)(.)[WITH]$2$1
-Jaaskinal: [REPLACEFIRST](.)(.*)[WITH]$2$1
-lessons and such (flesh out plox)
-fellow_starmadian: Regex101 - online regex editor and debugger
-Regex101 - format tester 2nd
-Regex101 - format tester
-Regex101 - use this as base for v2 of variable pointer system
-Jaaskinal: [REPLACEFIRST](.)(.*)[WITH]$2$1
-lessons and such (flesh out plox)
-fellow_starmadian: Regex101 - online regex editor and debugger
-Regex101 - format tester 2nd
-Regex101 - format tester
-Regex101 - use this as base for v2 of variable pointer system
Last edited: