regEx syntax for removal of first or last field in a string

    Fellow Starmadian

    Oh cool so thats what this is
    Joined
    Jun 7, 2014
    Messages
    227
    Reaction score
    87
    • Community Content - Bronze 1
    • Wired for Logic
    • Legacy Citizen 2
    BIG EDIT: This is no longer a question, but an answer.
    SECOND BIG EDIT: This is no longer a question, but an archived post. This thread has a more updated solution: RegEx compilation thread


    The question:
    So something has been bugging me for quite a while now, something that would totally revolutionize the starmade world. I've actually discussed this with a couple other users for a while now, and we can't find a solution so I'm forced to ask here.

    Is there any way to have a display read one word at a time, with multiple words on a single line? Something like this:

    [display 1] "the quick red fox jumps over the lazy brown dog"
    [display 2]REPLACEALL words 2 through 99 with " "

    and feed that statement through the first display block to be left with the word: "the "

    This is what I have so far, but it doesnt work. Might illustrate better what I wanted though:
    Regex101 - online regex editor and debugger

    The answer: Pt.1
    so I think I finally managed to get this to do half of what I want now, use this code to remove the first field from the string:

    [replaceall]^(?:[^:]*\:BACK PARENTHESES{1}([^:]*:BACK PARENTHESES [with]:

    (replace the capital words with one of these ")"

    the string has to start with a : Each field has to end with a : for the next field to start.
    EX: <:the super: A E S T H E T I C : ship: build:>

    then we just need one to remove the last field.

    edit: this is only half of what I need it to do, not all.
    so this removes the first occurence (or any number of occurences with the number in { }:
    [replaceall]^(?:[^:]*\:BACK PARENTHESES{1}([^:]*:BACK PARENTHESES [with]:

    The answer: Pt.2
    ok so here's the other part to this, it all had to do with this symbol "$" which forces regex to look at the end of the line, or something :/ anywho, here's the code:
    [replaceall]([^:]*:BACK PARENTHESES$[with]x

    Now I need a way to duplicate what the other part of the code does, which is replace the last field without having to use another display block with [del]1 so I can get rid of the X.

    update 1: use this code to delete any number of fields from the end that you like, just like the one that removes from the front: [replaceall]([^:]*BACK PARENTHESES{1}$[with]:

    still have to use [del]1 though afterwards..
    And this one removes the last occurrence:
    [replaceall]([^:]*:BACK PARENTHESES{1}$[with]:

    So My new question is this: How do you guys think this can be used? Here's a hasty and vague gif of how I intend to use it:
     
    Last edited:

    nightrune

    Wizard/Developer/Project Manager
    Joined
    May 11, 2015
    Messages
    1,324
    Reaction score
    577
    • Schine
    • Top Forum Contributor
    • Thinking Positive
    I think there are a number of ways to approach this. What is the end result you want? and what is the actual input?
     

    Jaaskinal

    ¯\_(ツ)_/¯
    Joined
    Jan 19, 2014
    Messages
    1,377
    Reaction score
    646
    • Legacy Citizen 4
    • Wired for Logic Gold
    • Thinking Positive
    I don't believe there's a fast way of doing this, but with instant pulses, regex, and DEL, you can do a lot of weird shit
     

    Fellow Starmadian

    Oh cool so thats what this is
    Joined
    Jun 7, 2014
    Messages
    227
    Reaction score
    87
    • Community Content - Bronze 1
    • Wired for Logic
    • Legacy Citizen 2
    well I want a way, in however many stages is required, to send each word to a different display block. obv. it has to be configured beforehand to a maximum number of words, I just don't know the regexp necessary to do it. So I guess I need a way to delete everything before the last word?
     

    Jaaskinal

    ¯\_(ツ)_/¯
    Joined
    Jan 19, 2014
    Messages
    1,377
    Reaction score
    646
    • Legacy Citizen 4
    • Wired for Logic Gold
    • Thinking Positive
    Thing is, it's really easy to parse backwards, i.e. remove one word at a time, compared to parsing forwards, adding one word at a time.
    I might try to do something with this tho.
     

    Fellow Starmadian

    Oh cool so thats what this is
    Joined
    Jun 7, 2014
    Messages
    227
    Reaction score
    87
    • Community Content - Bronze 1
    • Wired for Logic
    • Legacy Citizen 2
    so I think I finally managed to get this to do half of what I want now, use this code to remove the first field from the string:

    [replaceall]^(?:[^:]*\:BACK PARENTHESES{1}([^:]*:BACK PARENTHESES [with]:

    (replace the capital words with one of these ")"

    the string has to start with a : Each field has to end with a : for the next field to start.
    EX: <:the super: A E S T H E T I C : ship: build:>

    then we just need one to remove the last field.

    edit: this is only half of what I need it to do, not all.
     
    Last edited:

    Fellow Starmadian

    Oh cool so thats what this is
    Joined
    Jun 7, 2014
    Messages
    227
    Reaction score
    87
    • Community Content - Bronze 1
    • Wired for Logic
    • Legacy Citizen 2
    ok so here's the other part to this, it all had to do with this symbol "$" which forces regex to look at the end of the line, or something :/ anywho, here's the code:
    [replaceall]([^:]*:BACK PARENTHESES$[with]x

    Now I need a way to duplicate what the other part of the code does, which is replace the last field without having to use another display block with [del]1 so I can get rid of the X.

    update 1: use this code to delete any number of fields from the end that you like, just like the one that removes from the front: [replaceall]([^:]*BACK PARENTHESES{1}$[with]:

    still have to use [del]1 though afterwards..
    [doublepost=1485207738,1485207095][/doublepost]
    Thing is, it's really easy to parse backwards, i.e. remove one word at a time, compared to parsing forwards, adding one word at a time.
    I might try to do something with this tho.
    What do you mean by saying "add one word at a time."? adding words is easy, just use [add] :P
     
    Joined
    Jul 30, 2013
    Messages
    398
    Reaction score
    282
    • Wired for Logic Gold
    • Legacy Citizen 8
    • Purchased!
    What do you want to do, take a string of characters, and separate each "word/match" into a different display?
    for example:
    display 1 ":the super: A E S T H E T I C : ship: build:"
    display 2 ":the super:" ...
    display 3 ": A E S T H E T I C :" ...
    display 4 ":ship:" ...
    display 5 ":build:"

    is this correct?
     
    Joined
    Jul 30, 2013
    Messages
    398
    Reaction score
    282
    • Wired for Logic Gold
    • Legacy Citizen 8
    • Purchased!
    This is what you want to do?


    Code:
    This do 2 things, convert the first group in to a "non-group match" (This excludes the text of the captured group) and then select the rest of the string
    [REPLACEALL](?:(:\w+:))(.?)*[WITH]$1
    Regex101 - online regex editor and debugger
    Code:
    This other regex, select the first group match and replace with a empty refference using $3
    [REPLACEALL]^(:([^:]*:\s){1})()[WITH]$3
    Regex101 - online regex editor and debugger
     
    Last edited: