當前位置:首頁 » 編程語言 » java解析表達式

java解析表達式

發布時間: 2023-05-22 01:55:58

java,關系表達式,求運算過程解釋。謝謝。

因為&&是短路運算符「與」
((y=1)==0))&&((x=6)==6)), 當前面的表達式:((y=1)==0)) 為false的派行時候 ,後面的塵橡嘩表達式((x=6)==6)), 不會再執行了(因為「與」運算只要一個為false,就整個都false)
而:((y=1)==1))&&((x=6)==6)), 前面的表達式是true,那麼還要判斷後面的表達式的boolean值才能得到整個表達式的值,所以會執行((x=6)==6)),
希望對你有幫助

如果如嫌不清楚短路運算符,那你就把&& 換成& 去執行看看;(&是非短路」與「)

② Java中用正則表達式對於輸入數據的匹配和解析,求助!

我這樣寫都可以啊,用IE6,FIREFOX 3.0 都試過了前迅鎮,沒問題。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>慧粗 New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
Xhtml Linux
</BODY>
<script language="JavaScript">
document.body.innerHTML = document.body.innerHTML.replace(/(x)|(l)/gi,"<font color=red>$1$2</font>");
</script>
</HTML>

以下是通過FIREFOX 3.0 得到的BODY的innerHTM
<font color="red">X</font>htm<font color="red">l</font> <font color="red">L</font>inu<font color="red">x<昌蠢/font>
<script><font color=red>l</font>anguage="JavaScript">
document.body.innerHTM<font color=red>L</font> = document.body.innerHTM<font color=red>L</font>.rep<font color=red>l</font>ace(/(<font color=red>x</font>)|(<font color=red>l</font>)/gi,"<font co<font color=red>l</font>or=red>$1$2</font>");
</script>

③ JAVA正則表達式解析HTML字元串

public class TestString4 {
public static void main(String[] args) {
String s = "<R_Data> 0005,實驗室0,0,0|0101,實驗室A-測試點1,200,200|0102,實驗室C-測試點2,80,400|0109,實驗室C-測試點1,80,300|1020,實驗室C-測試點3,80,500|1141,實驗室A-測試點2,400,400|1146,實驗室A-測試點3,300,300|1239,實驗桐裂室B-測試點1,50,150|1240,實驗室B-測試點2,80,200|1264,實驗室B-測試點3,220,110| </R_Data>";
s = s.replace("<R_Data>", "").replace("</局乎閉R_Data>", "").trim();
String ss[] = s.split("\\|");
String[][] sss = new String[ss.length][];
for(int i=0;i<ss.length;i++){
sss[i] = ss[i].split(",");
}
}
}<p>sss中存頃困放的就是你需要的數據
</p>

④ java正則表達式解析Mysql資料庫錯誤日誌

System.out.println( new ReadSingleLineNumber().test2());
}

MySqlLog test2(){
String log = "2018-03-21T13:46:01.185376Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).";
String[] head = log.substring(0, log.indexOf(']') + 1).split(" ");
return new MySqlLog(head[0].trim(), Integer.parseInt(head[1].trim()), head[2].trim().substring(head[2].trim().indexOf('[') + 1, head[2].trim().indexOf(']')), log.substring(log.indexOf(']') + 2).trim());
}

class MySqlLog{
String time;
int index;
String level;
String msg;
public MySqlLog(String time, int index, String level, String msg) {
this.time = time;

⑤ Java解析excel 用正則表達式判斷日期格式去轉換到指定格式

^(\d{4}).?(\d{2}).?(\d{2})$
$1-$2-$3

⑥ Java中如何用正則表達式解析頁面,提取所有URL

先用正則表達式把所有的url找返態飢出來string reg = @"(?is)<a[^>]*href=(['""]?)(?<url>[^>'""閉猜\s]+)[^>]*>";然後再替換漏返掉你想要的

⑦ JAVA 文本表達式解析成數學公式,計算出結果

正則表達分解字元串
然後運算
給你個例子。以前寫的,現在忙沒空給你寫你這個了,public class CalStr { private String src;

/**
* constructor
*
* @param srcthe string(expression) to calculate
*/
public CalStr(String src) {
this.src = src;
}

/**
* calculate to get the result
*
* @return(double)result
*/
public double getResult() {
String postfix = getPostfix();
Stack stk = new Stack();
// System.out.println(postfix);
String parts[] = postfix.split( " + ");
double result = 0;
for (int i = 0; i < parts.length; i++) {
char tmp = parts[i].charAt(0);
if (!isOperator(tmp)) {
stk.push(parts[i]);
} else {
double a = Double.parseDouble((String) stk.pop());
double b = Double.parseDouble((String) stk.pop());
// b is followed by a in the orignal expression
result = calculate(b, a, tmp);
stk.push(String.valueOf(result));
}
}
return result;
}

/**
* test if the character is an operator,such +,-,*,/
*
* @param opthe character to test
* @returntrue if op is an operator otherwise false
*/
private boolean isOperator(char op) {
return (op == '+ ' || op == '- ' || op == '* ' || op == '/ ');
}

/**
* calculate an expression such (a op b)
*
* @param anumber 1
* @param bnumber 2
* @param opthe operator
* @return(double)(a op b)
*/
public double calculate(double a, double b, char op) {
switch (op) {
case '+ ':
return a + b;
case '- ':
return a - b;
case '* ':
return a * b;
case '/ ':
return a / b;
}
return -1;
}

/**
* convert the suffix to postfix
*
* @returnthe postfix as a string
*/
private String getPostfix() {
Stack stk = new Stack();
String postfix = new String();
char op;
int i = 0;
while (i < src.length()) {
if (Character.isDigit(src.charAt(i)) || src.charAt(i) == '. ') {
postfix += " ";
do {
postfix += src.charAt(i++);
} while ((i < src.length())
&& (Character.isDigit(src.charAt(i))));
postfix += " ";
}

else {
switch (op = src.charAt(i++)) {
case '( ':
stk.push( "( ");
break;

case ') ':
while (stk.peek() != "( ") {
String tmp = (String) stk.pop();
postfix += tmp;
if (tmp.length() == 1 && isOperator(tmp.charAt(0)))
postfix += " ";
}
stk.pop();
postfix += " ";
break;

case '+ ':
case '- ':
while ((!stk.empty()) && (stk.peek() != "( ")) {
postfix += stk.pop() + " ";
}
stk.push(String.valueOf(new Character(op)));
break;

case '* ':
case '/ ':
while ((!stk.empty())
&& ((stk.peek() == "* ") || (stk.peek() == "/ "))) {
postfix += stk.pop() + " ";
}
stk.push(String.valueOf(new Character(op)));
break;
}
}
}
ListIterator it = stk.listIterator(stk.size());
while (it.hasPrevious())
postfix += it.previous() + " ";
return postfix.trim().replaceAll( " +\\. ", ". ");
}

/**
* main function
*
* @param args
*/
public static void main(String args[]) {
System.out.println(new CalStr( "((1.5+6.000)*9+9.36)*(8+9-8*8+8*7) ")
.getResult());
}
}

⑧ java 怎麼用正則表達式解析sql中的表名,已有半成品,求改善

Stringstr="from\s+(.*)\s+where?";
Stringsql="select*fromtable,table2wherea=b";
Patternp=Pattern.compile(str);
Matchermatcher=p.matcher(sql);
while(matcher.find()){
Stringstring=matcher.group(1);
System.out.println(string);
}

⑨ java 正則表達式 解析sql文的表名,有半成品,求改進

試試這個


(?i)(?<=(?:from|into|update|join|)s*)w*[.]?w*(?=s*)

熱點內容
如何用計算器刷安卓 發布:2025-05-20 01:09:29 瀏覽:576
移動寬頻密碼重置後怎麼辦 發布:2025-05-20 01:02:04 瀏覽:808
php不是內部命令 發布:2025-05-20 00:41:09 瀏覽:97
淘寶圖片上傳用什麼軟體 發布:2025-05-20 00:40:55 瀏覽:346
mysql64位forlinux 發布:2025-05-20 00:37:25 瀏覽:345
工傷輔助器如何配置 發布:2025-05-20 00:25:13 瀏覽:602
opencv存儲圖片 發布:2025-05-20 00:16:10 瀏覽:953
ug編程鏈輪 發布:2025-05-20 00:14:03 瀏覽:100
手機鎖屏壁紙配置失敗怎麼解決 發布:2025-05-20 00:10:38 瀏覽:757
源碼編譯的軟體怎麼卸載 發布:2025-05-20 00:05:29 瀏覽:489