I want to detect the following:
window.location.href = "http://newlocation.com";
but not
window.location.href == "http://newlocation.com";
the query is ran in mySQL like so:
select "blablabla" REGEXP "bla"
Can't seem to get my head around this one.
SELECT 'window.location.href="http://newlocation.com"' REGEXP "href=\""
This gives me 1 (TRUE)
That one also
SELECT 'window.location.href="http://newlocation.com"' REGEXP "window\.location\.href=\"http:\/\/newlocation\.com\""
It depends what you want to match really.
There are two ways:
SELECT 'window.location.href = "http://www.google.com/"' REGEXP '[[:<:]]=[[:>:]]';
OR
SELECT 'window.location.href = "http://www.google.com/"' REGEXP ' = ';
Please note that both the above assume that there will be a space before and after the equals sign. If there might be no spaces before or after equals, you can try:
SELECT 'window.location.href = "http://www.google.com/"' REGEXP '[^=]+=[^=]+';
I'm not sure about the last one but it should work.
Hope it helps!
Related
I have this snippet:
SELECT
CASE WHEN
AVG(UNIX_TIMESTAMP(tDone)-UNIX_TIMESTAMP(tIPN))/3600 >= 10
THEN
ROUND(AVG(UNIX_TIMESTAMP(tDone)-UNIX_TIMESTAMP(tIPN))/3600,0)
ELSE
ROUND(AVG(UNIX_TIMESTAMP(tDone)-UNIX_TIMESTAMP(tIPN))/3600,1)
END
FROM
...
Can I do anything to remove the duplication from this? Something along these lines, for instance: (Hypothetical code follows):
SET var = AVG(UNIX_TIMESTAMP(tDone)-UNIX_TIMESTAMP(tIPN))/3600
SELECT
CASE WHEN
var > 10
THEN
ROUND(var,0)
ELSE
ROUND(var,1)
END
FROM
...
With a subquery you can do something like this :
SELECT
CASE WHEN avgtiPN >= 10 THEN ROUND(avgtiPN,0) ELSE ROUND(avgtiPN,1) END
FROM
(SELECT
AVG(UNIX_TIMESTAMP(tDone)-UNIX_TIMESTAMP(tIPN))/3600 AS avgtiPN
FROM
...) AS AVGQuery
But I am still uncertain if it is more readable.
Yes, you can, but variable processing order is undefined for user-defined variables. This reference in the MySQL documentation explains when this works and when it doesnt.
I would like to do a replace with two characters.
Below is my code, my problem is now i need to replace '/' as well rather than just '-', run replace twice is not really a good idea, and i am pretty bad at regular expression. Is anyone can help me write a RegExp which will search the whole string and replace any '-' o r'/' have.
var myPattern:RegExp = / /gi;
productId.replace(myPattern, '-')
Match any character within [] of your RegEx.
To replace both "/" and " " (space):
replace(/[\/ ]/g, "-");
Example:
var s:String = "2012/10/29 12:29";
trace(s.replace(/[\/ ]/g, "-"));
Would produce:
2012-10-29-12:29
this should replace any '/' or '-' in your productId string to a '$'
var myPattern:RegExp = /[\/-]/g;
productId.replace(myPattern, '$');
(ab+cd)(a'b'+c'd') = 1+ abc'd' + a'b'cd +1
so I'm stuck at
abc'd'+a'b'cd
but the final answer is
(a+b)(c+d)+(a'+b')(c'+d')
What am I missing?
It seems to me that those two expressions are complementary, i.e. the only two cases where (a+b)(c+d)+(a'+b')(c'+d') are false are abc'd' and a'b'cd.
Edit: Somewhere along the line I think you've lost a ' and you're actually looking for one of these:
((ab+cd)(a'b'+c'd'))'
(ab+cd)'+(a'b'+c'd')'
((ab)'(cd)')+((a'b')'(c'd')')
(a'+b')(c'+d')+(a+b)(c+d)
(a+b)(c+d)+(a'+b')(c'+d')
(ab+cd)(a'b'+c'd')
(a'b'+c'd')(ab+cd)
((a+b)'+(c+d)')((a'+b')'+(c'+d')')
((a+b)(c+d))'((a'+b')(c'+d'))'
((a+b)(c+d)+(a'+b')(c'+d'))'
you cannot prove that (ab+cd)(a'b'+c'd') = (a+b)(c+d)+(a'+b')(c'+d') because it is not true.
take a=b=1, c=d=0:
(ab+cd)(a'b'+c'd') = (1+0)(0+1) = 1
but
(a+b)(c+d)+(a'+b')(c'+d') = (1*0)+(0*1) = 0
(assuming x' is "not")
I'm trying to split an HTML document into its head and body:
my #contentsArray = split( /<\/head>/is, $fileContents, 1);
if( scalar #contentsArray == 2 ){
$bodyContents = $dbh->quote(trim($contentsArray[1]));
$headContents = $dbh->quote(trim($contentsArray[0]) . "</head>");
}
is what i have. $fileContents contains the HTML code. When I run this, it doesn't split. Any one know why?
The third parameter to split is how many results to produce, so if you want to apply the expression only once, you would pass 2.
Note that this does actually limit the number of times the pattern is used to split the string (to one fewer than the number passed), not just limit the number of results returned, so this:
print join ":", split /,/, "a,b,c", 2;
outputs:
a:b,c
not:
a:b
sorry, figured it out. Thought the 1 was how many times it would find the expression not limit the results. Changed to 2 and works.
SELECT ica.CORP_ID, ica.CORP_IDB, ica.ITEM_ID, ica.ITEM_IDB,
ica.EXP_ACCT_NO, ica.SUB_ACCT_NO, ica.PAT_CHRG_NO, ica.PAT_CHRG_PRICE,
ica.TAX_JUR_ID, ica.TAX_JUR_IDB, ITEM_PROFILE.COMDTY_NAME
FROM ITEM_CORP_ACCT ica
,ITEM_PROFILE
WHERE (ica.CORP_ID = 1000)
AND (ica.CORP_IDB = 4051)
AND (ica.ITEM_ID = 1000)
AND (ica.ITEM_IDB = 4051)
AND ica.EXP_ACCT_NO = ITEM_PROFILE.EXP_ACCT_NO
I'm trying basically say since the exp account code is '801500' then the Name should return "Miscellaneous Medic...".
It seems as if what you are showing is not possible. Have you edited the data in the editor??? You are joining using ica.EXP_ACCT_NO = ITEM_PROFILE.EXP_ACCT_NO . Therefore, every entry with EXP_ACCT_NO = 801500, should also have the same COMDTY_NAME.
However, it could be the case that your IDs are not actually numbers and that they are strings with whitespace (801500__ vs 801500 ). But since you are not performing a left-outer join, it would also mean you have an entry in ITEM_PROFILE with the same whitespace.
You also need to properly normalize your table data (unless this is a view) but it still means you have erroneous data.
Try to perform the same query, but using the TRIM function to remove whitespace: https://stackoverflow.com/a/6858168/1688441 .
Example:
SELECT ica.CORP_ID, ica.CORP_IDB, ica.ITEM_ID, ica.ITEM_IDB,
ica.EXP_ACCT_NO, ica.SUB_ACCT_NO, ica.PAT_CHRG_NO, ica.PAT_CHRG_PRICE,
ica.TAX_JUR_ID, ica.TAX_JUR_IDB, ITEM_PROFILE.COMDTY_NAME
FROM ITEM_CORP_ACCT ica
,ITEM_PROFILE
WHERE (ica.CORP_ID = 1000)
AND (ica.CORP_IDB = 4051)
AND (ica.ITEM_ID = 1000)
AND (ica.ITEM_IDB = 4051)
AND trim(ica.EXP_ACCT_NO) = trim(ITEM_PROFILE.EXP_ACCT_NO);