[Solved] Echapped " not working in variable

0 favourites
  • 12 posts
From the Asset Store
Color Variable
$4.50 USD
10% off
Easily store, modify, read and manipulate colors with Color Variables!
  • So this is pretty simple:

    I have an event that test if a text matches a regex, so far it does nothing but telling me whether it does and it works prefectly, the text matches as intended.

    Then, because I plan to reuse the same Regex several times in the code, I decide instead to put it into a variable and call the variable.

    And as simple as this, it doesn't work anymore ?!

    The code is quasi-literally limited to this event, so I beside double-checking the spelling, I really have no idea where to look for a mistake. :/

    Update:

    It has to do with the fact I'm using " within the regex.

    Usually you can include a " within a string by typing it "", that's what I did with the event and it works there. Then I just copy-pasted the regex into the variable. The variable does work if I shorten my regex to a bit without "", but as soon as I bring it back it stops working.

  • works for me with a simpler example:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think I located the problem, but that doesn't come with a solution yet.

    It has to do with the fact I'm using " within the regex.

    Usually you can include a " within a string by typing it "", that's what I did with the event and it works there. Then I just copy-pasted the regex into the variable. The variable does work if I shorten my regex to a bit without "", but as soon as I bring it back it stops working.

  • Manual says: Double quotes can be used as an escape character in any string.

    Strings (text)

    Text is also known as strings in programming, and Construct 2 also sometimes uses this naming convention. Text in expressions should be surrounded by double-quotes, e.g. "Hello"

    The double-quotes are not included as part of the text, so setting a text object to show the expression "Hello" will make it show Hello, without any double-quotes. To include a double-quote in a string, use two double-quotes next to each other (""), e.g. "He said ""hi"" to me" will return He said "hi" to me.

  • 99Instances2Go

    Yes, I know that, that's what I've been doing up there: typing class=""x"" so it understands class="x", but yet it still only works half the times.

  • Sorry that i was of no use for you.

    What if you break it down in 2 string ?

    A = "regex thing class=""x"

    B = ""therestofhtethig

    regex = A&B

    Probaly again of no use.

  • I don't think so, a single double double-quote is enough to make the regex not match the string, so beside with far-fetched combinations of variables, which would break the whole point of using variables, I don't see how I could stealthily include a double-quote in there.

    Any moderator, I'm starting to wonder if it wouldn't be worth moving this into the bug section ?

  • I fail to see what's wrong:

    in the TextBox I put:

    <a href="http://www.google.com">Google</a>

    and I got "Match"

  • trueicecold

    What's wrong in your example is that you didn't use echapped doublequotes. ( "" )

    I put href= alone in your textbox and got a match although it shouldn't work.

    In your case construct is actually testing for the regex href= , not the regex href=".+" which you should have written href="".+""

    However, it would work fine with href='.+'

  • Estecka, I couldn't reproduce the scenario you're talking about... I put href= in the textbox, and I don't get a match...

    Why use double quotes in the first place? Have you create a variable and started its value with quotes? No need to, just write the value without the quotes at the beginning and at the end, construct wraps it for you...

    Attached a capx

    https://drive.google.com/file/d/0B5myBvkaZTxscE5yQUczVUhEeVU/view?usp=sharing

  • trueicecold Argh my bad. >_<

    I didn't spell the "no" in "no match". I'm so dumb.

    Yet I fail to understand, why do we need to escape the double-quote in the event, but not in the variable ?

  • Because you already defined the variable as String, so Construct wraps it as a string for you anyways... In the event, you can type literally anything, so you must declare it as a string using double quotes.

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