I'd like to remove this part :
"company.html?#{token_url}&company=#{URI.encode(current_company.trylive_name)}" but an error appears syntax error, unexpected '}', expecting ':'
#iframe_statistics_url = "#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/#{current_user.has_role?(:administrator) ? "companies.html?#{admin_token_url}" : "company.html?#{token_url}&company=#{URI.encode(current_company.trylive_name)}"}"
You can't use double quotes(") inside double quotes. You need to escape those quotes:
"Hello, "are you there?" # doesn't make sense in Ruby
"Hello, \"are you there?" # escaped double quotes inside the string
#VtrKanna
#iframe_statistics_url = "#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/#{current_user.has_role?(:administrator) ? "companies.html?#{admin_token_url}" : "company.html?#{token_url}&company=#{URI.encode(current_company.trylive_name)}"}"
this is work fine
but my problem is just to keep this part
#iframe_statistics_url = "#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/#{current_user.has_role?(:administrator) ? "companies.html?#{admin_token_url}"}"
this is result an error
Try like this
val = current_user.has_role?(:administrator) ? "companies.html?#{admin_token_url}" : "company.html?#{token_url}&company=#{URI.encode(current_company.trylive_name)}"
#iframe_statistics_url = "#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/}#{val}"
Or
g = "https://www.google.co.in/"
q = %[helo #{"world #{g}"}]
=> "helo world https://www.google.co.in/"
Try it
#iframe_statistics_url = %[#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/companies.html?#{current_user.has_role?(:administrator) ? admin_token_url : "#{token_url}&company=#{URI.encode(current_company.trylive_name)}"}]
Related
I have a string for which the last (dot) need to replaced with "_"
x = "W1-9007-abc_1.0.ns" -- Other example: W1-9007-abc_1.0.0.ns -> W1-9007-abc_1.0.0_ns
Expected Output:
x = "W1-9007-abc_1.0_ns"
Reference:
I have tried this reference without much luck.
Reference: stackoverflow.com/a/45263473/2986344
Solution that worked:
x = "W-9007-mnist_1.0.0.ms"
x = x:gsub("(.*)[%p]", "%1_")
print(x)
Alternative solution:
local before_dot, after_dot = str:match"(.*)%.(.-)$"
str = before_dot .. "_" .. after_dot
I would like to check if a string contains any of the following symbols ^ $ * . [ ] { } ( ) ? - " ! # # % & / \ , > < ' : ; | _ ~ ` + =
I tried using the following
string.contains(RegExp(r'[^$*.[]{}()?-"!##%&/\,><:;_~`+=]'))
But that does not seem to do anything. I am also not able to add the ' symbol.
Questions:
How do I check if a string contains any one of a set of symbols?
How do I add the ' symbol in my regex collection?
When writing such a RegExp pattern, you should escape the special symbols (if you want to search specifically by them).
Also, to add the ' to the RegExp, there is no straightforward way, but you could use String concatenation to work around this.
This is what the final result could look like:
void main() {
final regExp = RegExp(
r'[\^$*.\[\]{}()?\-"!##%&/\,><:;_~`+=' // <-- Notice the escaped symbols
"'" // <-- ' is added to the expression
']'
);
final string1 = 'abc';
final string2 = 'abc[';
final string3 = "'";
print(string1.contains(regExp)); // false
print(string2.contains(regExp)); // true
print(string3.contains(regExp)); // true
}
To ad both ' an " to the same string literal, you can use a multiline (triple-quoted) string.
string.contains(RegExp(r'''[^$*.[\]{}()?\-"'!##%&/\\,><:;_~`+=]'''))
You also need to escape characters which have meaning inside a RegExp character class (], - and \ in particular).
Another approach is to create a set of character codes, and check if the string's characters are in that set:
var chars = r'''^$*.[]{}()?-"'!##%&/\,><:;_~`+=''';
var charSet = {...chars.codeUnits};
var containsSpecialChar = string.codeUnits.any(charSet.contains);
I have this concrete syntax:
syntax SomeMore = [...] SyncBlock? sync;
syntax SyncBlock = "sync" "{" SyncStatement* stats "}";
syntax SyncStatement = [...];
[SyncBlock]"sync { <syncStrings> }" seems to work, but when I try to use it as a SyncBlock? and assign it:
SyncBlock? sync = [SyncBlock?]"sync { <syncStrings> }"
it does not work: inline parsing not supported on SyncBlock?, what is the easiest way to build up a value of this X?-type?
Can I convert a SyncBlock to a SyncBlock? somehow?
Something like this also doesn’t work:
syncBlock = (SyncBlock?)`sync { <SyncStatement* syncs>}`;
P.S. SyncBlock? syncBlock = … results in Ambiguous code (internal error), SyncBlock? syncBlock = …. Probably due to a ternary operator ambiguity?
I found a workaround, not ideal, but it works.
It seems that the ? in the types introduces some difficulties, but can be circumvented using an "alias" for this type:
I changed the grammar to:
syntax SomeMore = [...] MaybeSyncBlock sync;
syntax MaybeSyncBlock = SyncBlock?;
syntax SyncBlock = "sync" "{" SyncStatement* stats "}";
syntax SyncStatement = [...];
Now this works:
MaybeSyncBlock syncBlock = [MaybeSyncBlock]"sync { <syncStrings> }";
I'm programming User Defined Views in a Rails app. I have a table called uvcondtions that contains the column(field_name), condition(condition), and compared to (ucompare) to information.
For example:
Field_name = description
ucondition = like
ucompare = Truck
Gets turned into where table_name.description like "Truck"
It's working great for most PG SQL conditions. The in condition doesn't work.
If I have this in the uvconditions record:
field_name = id
uvcondition = in
uvcompare = (1,3)
I get this error:
PG::Error: ERROR: syntax error at or near " '(1,3)' "
LINE 1: ...sts" WHERE "worequests"."tenant_id" = 1 AND (id in '(1,3)')
This is the statements that create the where clause:
uvc = uvcondition.ucompare if uvcondition.ucondition == 'in'
#worequests = Worequest.where( uvcondition.field_name + " " + uvcondition.ucondition + " ?", uvc )
Is there any way to remove the quotes around uvc ??
Thanks for the help!
The error is occuring because uvc is actually a string:
uvc = "(1,3)"
Which misleads Rails to sanitize this string before using it in the SQL query (puttin the extra quotes). Instead of this behavior, Rails should create a list of possible values, made from an Array.
Make uvc a Ruby array and it should solve your problem:
uvc = [1, 3]
#worequests = Worequest.where(uvcondition.field_name + " " + uvcondition.ucondition + " ?", uvc)
I want to replace a word into my body content from other string .
To implement this i am using ngx.re.sgub but i am getting a weird issue. ngx.re.gsub is not handling magic characters.
Example :
content1 = "HiTestHello Test how are you Testall "
_ssi = "Test"
body = "$100.00"
content2 = ngx.re.gsub(content1, _ssi, body)
ngx.print(content2)
output is
Hi.00lHelo .00 how are you .00all he.00llo .00 how are you .00all
while output should like :
Hi$100.00Hello .00 how are you .00all.
Please let me know how can i achieve this .
In ngx regex, $1, $2, etc. are variable to be captured. Try escape the $ character:
body = "$$100.00"
Wrap the body with a function also avoids it:
content1 = "HiTestHello Test how are you Testall "
_ssi = "Test"
body = "$100.00"
content2 = ngx.re.gsub(content1, _ssi, function()
return body
end, "o")
ngx.print(content2)