[Solved] Echapped " not working in variable

Get help using Construct 2

Post » Mon Jun 27, 2016 5:24 pm

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.
Image

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.
Image

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.
Last edited by Estecka on Tue Jun 28, 2016 9:45 pm, edited 8 times in total.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Mon Jun 27, 2016 5:56 pm

works for me with a simpler example:

Image
B
18
S
7
G
1
Posts: 157
Reputation: 1,928

Post » Mon Jun 27, 2016 10:16 pm

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.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Mon Jun 27, 2016 10:37 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Jun 27, 2016 10:47 pm

@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.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Mon Jun 27, 2016 11:18 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Jun 27, 2016 11:55 pm

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 ?
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Tue Jun 28, 2016 6:54 pm

I fail to see what's wrong:

Image

in the TextBox I put:

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

and I got "Match"
B
18
S
7
G
1
Posts: 157
Reputation: 1,928

Post » Tue Jun 28, 2016 7:37 pm

@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='.+'
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Tue Jun 28, 2016 8:32 pm

@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
B
18
S
7
G
1
Posts: 157
Reputation: 1,928

Next

Return to How do I....?

Who is online

Users browsing this forum: diamantico21, ratboy3, TRMG and 43 guests