匹配純數字數學公式的正規表示式

2021-08-31 12:55:03 字數 819 閱讀 4556

<%@ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="_default" %>

using system.collections.generic;

using system.linq;

using system.web;

using system.web.ui;

using system.web.ui.webcontrols;

using system.text.regularexpressions;

public partial class _default : system.web.ui.page

}protected void check_click(object sender, eventargs e)

else}}

其中這裡的這則表示式

string pattern = @"^(\(*\d+(.\d+)*\)*(\+|-|/|\*))+\d+(.\d+)*\)*$";

表示的是類似這樣的數學公式((1.2+1)*2.8+3)/4

只是簡單的匹配,不是很嚴謹

\d+(.\d+)* 代表整數或小數

\(*代表0個或多個(

(\+|-|/|\*) 這個表示+、-、*、/中的乙個對於正規表示式有用到的特殊符號,要用\來轉意一下,比如在正規表示式中+代表其前面的字元有1個或多個,所以要表示+的時候要用\+來表達

asp正規表示式匹配數字 數字 數字

複製 如下 dim strok,strno strok 12312321 12312312312 12312321 strno 12312321 12312312312 12312321 sdfsd function regexptest patrn,strng ncsxlqbsp dim rege...

正規表示式 匹配

字串 void abtr quint32 ab 表示乙個正規表示式 template class bidirectionaliterator class allocator std allocator sub match bidirectionaliterator class match resul...

正規表示式匹配

請實現乙個函式用來匹配包括 和 的正規表示式。模式中的字元 表示任意乙個字元,而 表示它前面的字元可以出現任意次 包含0次 在本題中,匹配是指字串的所有字元匹配整個模式。例如,字串 aaa 與模式 a.a 和 ab ac a 匹配,但是與 aa.a 和 ab a 均不匹配 解法 首先要想到用遞迴處理...