How do I use RegExp to remove text before and after?

0 favourites
  • 5 posts
From the Asset Store
Customize the animation of character when item changed
  • Hello! I need your help. I've been searching for 2 days and still can't wrap my head around how RegExp works. I've even tried doing some exercices to understand how to use it but it seems so complicated...

    I have a log which I save in a Text value, let's call it TextLog.

    Now the data it contains can be divided in 3 portions who are respectively in bold,italic and underlined. It looks like this

    "Always same text... random text... always same text. Middle of log text beginning with same text always... random text and ends with always same text.Now 3rd section always same text...random text...ends with always same text"

    I only need to keep the Middle portion.

    Which RegExp do I use in Construct 2, RegExMatch? RegExSearch? RegExReplace? and what do I put as values? RegexMatchAt(String, Regex, Flags, Index).

  • I don't know how to do this with regex, but you can use find, mid, left, right and len expressions.

    For example:

    set log to right(log, len(log)-(find(log, "start text")+1))

    set log to left(log, len(log)-(find(log, "end text")+1))

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • +1)) would mean +1 character so I would need to have an exact number of characters all the time? or is it for a paremeter.

    I'll try it right now

  • seems like it's working! Thanks a lot dop2000

  • Here,s the regex answer.

    Explanation

    /

    (?<=start text\s).*(?=\send text)

    /

    Positive Lookbehind (?<=start text\s)

    Assert that the Regex below matches

    start text matches the characters start text literally (case sensitive)

    \s matches any whitespace character (equal to [\r\n\t\f\v ])

    .* matches any character (except for line terminators)

    * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)

    Positive Lookahead (?=\send text)

    Assert that the Regex below matches

    \s matches any whitespace character (equal to [\r\n\t\f\v ])

    end text matches the characters end text literally (case sensitive)

    Cheers

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)