relay_api.php

Just sticking this here for anybody that wants to use it.

Haven't done much with JSON, but if you're fine with PHP then this is a handy script to make the calls and grab the return data, and it also helps to make the data easier to look at (for human eyes).
You can still use JSON, but for now it just returns the data raw.

I may or may not update this sporadically, or if there's something you'd like to see put in, go ahead and leave a comment and I'll see if I'm up to the challenge.

----
Oh! If someone can help with regex (or know a quick painless way to check) there's one thing this script needs and that's when it's checking for an end of line quote... is there an easy way to say "match a quote character preceded by an EVEN number of backslashes (including zero)"?

I'm trying to refrain from just deleting pairs of backslashes and then seeing if I have one or none left.
 

Attachments

  • relay_api.php.ash
    6.6 KB · Views: 50
Regex:
Code:
"(?!<\\)(\\\\)*\"$"

I think. Java supports negative lookbehind, right?
So, that'd have to be...
"(?!<\\\\)(\\\\\\\\)*'$" in ASH ... each two become one in ash, so every four becomes one in regex...
Uuuugh.
Thanks, I would have never thought of that.
 
Last edited:

heeheehee

Developer
Staff member
Nonono, it's already escaped for ASH. The idea is that you have an even number of backslashes (2 * x) followed by a quotation mark and EOL and not preceded by a backslash.
 

Alhifar

Member
\\ in ash converts to \ in regex, which means it needs escaped again to keep from matching a literal ), unless I'm misunderstanding something
 

Theraze

Active member
Isn't the ending quotation mark there to say that the section begun by the beginning quotation mark is now ending? It doesn't seem like you'd want to escape that...
 

heeheehee

Developer
Staff member
If the string is denoted by double-quotation marks, the quotation mark should be singly-escaped so that it doesn't end the string, right?
 

Theraze

Active member
Nope. You're ending the string with the matching of $. The " ends and begins your regexp. So if you escape the final one, it's going to try to keep matching the rest of your code...
 

Catch-22

Active member
Nope. You're ending the string with the matching of $. The " ends and begins your regexp. So if you escape the final one, it's going to try to keep matching the rest of your code...

What heeheehee means is the string would terminate prematurely if you didn't escape the ", so the final ASH string would look like this:

PHP:
"(?!<\\\\)(\\\\\\\\)*\\\"$"

The unescaped matcher string would look like this:

Code:
(?!<\\\\)(\\\\\\\\)*\\"$

and the regular expression looks like this:

Code:
(?!<\\)(\\\\)*\"$
 
Last edited:

slyz

Developer
Does the " need to be escaped in RegEx? If not, shouldn't it be:
Code:
string matcher = "(?!<\\\\)(\\\\\\\\)*\"$"
 

slyz

Developer
" doesn't seem to be a special character, so it doesn't need to be escaped in RegEx apparently. Another little fix:
Code:
?!<
should be
Code:
?<!

It seems to work. I entered a couple of examples in a text file (to avoid having to figure out how many times to escape special characters):
Code:
0	"Blablabla and \\\ and also \\ oh and \\\"
1	"Did I forget about \\\\"
and ran the following scriptlet:
PHP:
string expr = "(?<!\\\\)(\\\\\\\\)*\"$";

string [ int ] text;
file_to_map( "test.txt", text );

foreach i, str in text
{
	print( "" );
	print( "string: " + str );

	matcher m = create_matcher( expr, str );
	boolean found = false;
	while ( m.find() )
	{
		print( "match found: " + m.group( 0 ) );
		found = true;
	}

	if ( !found ) print( "no match found" );
}
I got the following results:
Code:
> call test.ash

string: "Blablabla and \\\ and also \\ oh and \\\"
no match found

string: "Did I forget about \\\\"
match found: \\\\"
 
Last edited:
Thanks for all the discussion guys, but you seem to be overlooking that the string is defined in double-quotes, but I'm only matching for a single quote. The single quote need not be escaped in ASH, and quotes (hesitate to use this word) never need to be escaped in regex.
 

Catch-22

Active member
Well, I guess you could call it an old habit, I escape everything that isn't alphanumeric in a regular expression. Slyz is probably right in that only metacharacters have a requirement to be escaped, but if you're not really sure if something is a metacharacter or otherwise (given there are several different regular expression engine implementations around), I don't think it hurts to just escape anything that isn't alphanumeric.

Also, by single quote I assume you mean apostrophe :p

Either way, I believe there should be more than enough information here to answer your original question. As always, test the code before you release it :)
 
Last edited:
Top