中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

蘄春做網(wǎng)站google瀏覽器入口

蘄春做網(wǎng)站,google瀏覽器入口,網(wǎng)站遷移到別的服務(wù)器要怎么做,飲料網(wǎng)站建設(shè)市場分析系列文章目錄 unity工具 文章目錄 系列文章目錄前言一、匹配正整數(shù)的使用方法1-1、代碼如下1-2、結(jié)果如下 二、匹配大寫字母2-1、代碼如下1-2、結(jié)果如下 三、Regex類3-1、Match()3-2、Matches()3-3、IsMatch() 四、定義正則表達(dá)式…

系列文章目錄

unity工具


文章目錄

  • 系列文章目錄
  • 前言
  • 一、匹配正整數(shù)的使用方法
    • 1-1、代碼如下
    • 1-2、結(jié)果如下
  • 二、匹配大寫字母
    • 2-1、代碼如下
    • 1-2、結(jié)果如下
  • 三、Regex類
    • 3-1、Match()
    • 3-2、Matches()
    • 3-3、IsMatch()
  • 四、定義正則表達(dá)式
    • 4-1、轉(zhuǎn)義字符
    • 4-2、字符類
    • 4-3、定位點(diǎn)
    • 4-4、限定符
  • 五、常用的正則表達(dá)式
    • 5-1、校驗(yàn)數(shù)字的表達(dá)式
    • 5-2、校驗(yàn)字符的表達(dá)式
    • 5-3、校驗(yàn)特殊需求的表達(dá)式
  • 六、正則表達(dá)式實(shí)例
    • 6-1、匹配字母的表達(dá)式
    • 6-2、替換掉空格的表達(dá)式
  • 七、完整的測試代碼
  • 總結(jié)


在這里插入圖片描述

前言

大家好,我是心疼你的一切,不定時更新Unity開發(fā)技巧,覺得有用記得一鍵三連哦。
正則表達(dá)式,又稱規(guī)則表達(dá)式,在代碼中常簡寫為regex、regexp,常用來檢索替換那些符合某種模式的文本。
許多程序設(shè)計(jì)語言都支持利用正則表達(dá)式進(jìn)行字符串操作。


提示:以下是本篇文章正文內(nèi)容,下面案例可供參考

unity使用正則表達(dá)式

一、匹配正整數(shù)的使用方法

1-1、代碼如下

using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
/// <summary>
/// 匹配正整數(shù)
/// </summary>
public class Bool_Number : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){string num = "456";Debug.Log("結(jié)果是:"+IsNumber(num));}public bool IsNumber(string strInput){Regex reg = new Regex("^[0-9]*[1-9][0-9]*$");if (reg.IsMatch(strInput)){return true;}else{return false;}}
}

1-2、結(jié)果如下

在這里插入圖片描述

二、匹配大寫字母

檢查文本是否都是大寫字母

2-1、代碼如下

using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
/// <summary>
/// 匹配大寫字母
/// </summary>
public class Bool_Majuscule : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){string NUM = "ABC";Debug.Log("NUM結(jié)果是:" + IsCapital(NUM));string num = "abc";Debug.Log("num結(jié)果是:" + IsCapital(num));}public bool IsCapital(string strInput){Regex reg = new Regex("^[A-Z]+$");if (reg.IsMatch(strInput)){return true;}else{return false;}}
}

1-2、結(jié)果如下

在這里插入圖片描述

三、Regex類

正則表達(dá)式是一種文本模式,包括普通字符和特殊字符,正則表達(dá)式使用單個字符描述一系列匹配某個句法規(guī)則的字符串 常用方法如下在這里插入圖片描述
如需了解更詳細(xì)文檔請參考:https://www.runoob.com/csharp/csharp-regular-expressions.html

3-1、Match()

測試代碼如下

using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;public class Bool_Regex_Match : MonoBehaviour
{void Start(){string temp = "aaaa(bbb)cccccc(dd)eeeeee";IsMatch(temp);}///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch(string strInput){string pattern = "\\(\\w+\\)";Match result = Regex.Match(strInput, pattern);Debug.Log("第一種重載方法:" + result.Value);Match result2 = Regex.Match(strInput, pattern, RegexOptions.RightToLeft);Debug.Log("第二種重載方法:" + result2.Value);}}

測試結(jié)果
在這里插入圖片描述

3-2、Matches()

代碼如下:

using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;public class Bool_Regex_Matches : MonoBehaviour
{void Start(){string temp = "aaaa(bbb)aaaaaaaaa(bb)aaaaaa";IsCapital(temp);}///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)///</summary>///<param name="strInput">輸入的字符串</param>public void IsCapital(string strInput){string pattern = "\\(\\w+\\)";MatchCollection results = Regex.Matches(strInput, pattern);for (int i = 0; i < results.Count; i++){Debug.Log("第一種重載方法:" + results[i].Value);}MatchCollection results2 = Regex.Matches(strInput, pattern, RegexOptions.RightToLeft);for (int i = 0; i < results.Count; i++){Debug.Log("第二種重載方法:" + results2[i].Value);}}
}

結(jié)果如下
在這里插入圖片描述

3-3、IsMatch()

代碼如下:

using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;public class Bool_Regex_IsMatch : MonoBehaviour
{void Start(){string temp = "aaaa(bbb)cccccc(dd)eeeeeeee";IsMatch(temp);}///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch(string strInput){string pattern = "\\(\\w+\\)";bool resultBool = Regex.IsMatch(strInput, pattern);Debug.Log(resultBool);bool resultBool2 = Regex.IsMatch(strInput, pattern, RegexOptions.RightToLeft);Debug.Log(resultBool2);}
}

結(jié)果如下
在這里插入圖片描述

四、定義正則表達(dá)式

4-1、轉(zhuǎn)義字符

總結(jié):在這里插入圖片描述

方法如下:

  ///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (轉(zhuǎn)義字符)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch(string strInput){string pattern = "\\r\\n(\\w+)";Match resultBool = Regex.Match(strInput, pattern);Debug.Log(resultBool.Value);}

4-2、字符類

總結(jié):
在這里插入圖片描述

方法如下:

  ///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng) (字符類)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_1(string strInput){string pattern = "(\\d+)";Match resultBool = Regex.Match(strInput, pattern);Debug.Log(resultBool.Value);}

4-3、定位點(diǎn)

正則表達(dá)式中的定位點(diǎn)可以設(shè)置匹配字符串的索引位置,所以可以使用定位點(diǎn)對要匹配的字符進(jìn)行限定,以此得到想要匹配到的字符串
總結(jié):在這里插入圖片描述
方法代碼如下:

 ///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng) (定位點(diǎn))///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_2(string strInput){string pattern = "(\\w+)$";Match resultBool = Regex.Match(strInput, pattern);Debug.Log(resultBool.Value);}

4-4、限定符

正則表達(dá)式中的限定符指定在輸入字符串中必須存在上一個元素的多少個實(shí)例才能出現(xiàn)匹配項(xiàng)
在這里插入圖片描述
方法如下:

 ///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (限定符)///</summary> ///<param name="strInput">輸入的字符串</param>public void IsMatch_3(string strInput){string pattern = "\\w{5}";Match resultBool = Regex.Match(strInput, pattern);Debug.Log(resultBool.Value);}

五、常用的正則表達(dá)式

5-1、校驗(yàn)數(shù)字的表達(dá)式

代碼如下:

  ///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (常用的校驗(yàn)數(shù)字表達(dá)式)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_4(string strInput){Regex reg = new Regex(@"^[0-9]*$");bool result = reg.IsMatch(strInput);Debug.Log(result);}

5-2、校驗(yàn)字符的表達(dá)式

字符如果包含漢字 英文 數(shù)字以及特殊符號時,使用正則表達(dá)式可以很方便的將這些字符匹配出來
代碼如下:

///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (常用的校驗(yàn)字符表達(dá)式)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_5(string strInput){Regex reg = new Regex(@"^[\u4E00-\u9FA5A-Za-z0-9]");bool result = reg.IsMatch(strInput);Debug.Log("匹配中文、英文和數(shù)字:" + result);Regex reg2 = new Regex(@"^[A-Za-z0-9]");bool result2 = reg2.IsMatch(strInput);Debug.Log("匹配英文和數(shù)字:" + result2);}

5-3、校驗(yàn)特殊需求的表達(dá)式

方法如下:

 ///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (常用的校驗(yàn)特殊需求的表達(dá)式)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_6(){Regex reg = new Regex(@"[a-zA-z]+://[^\s]*");bool result = reg.IsMatch("http://www.baidu.com");Debug.Log("匹配網(wǎng)址:" + result);Regex reg2 = new Regex(@"^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$");bool result2 = reg2.IsMatch("13512341234");Debug.Log("匹配手機(jī)號碼:" + result2);}

六、正則表達(dá)式實(shí)例

(經(jīng)常用到的)

6-1、匹配字母的表達(dá)式

開發(fā)中經(jīng)常要用到以某個字母開頭或某個字母結(jié)尾的單詞

下面使用正則表達(dá)式匹配以m開頭,以e結(jié)尾的單詞
代碼如下:

///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (匹配以m開頭,以e結(jié)尾的表達(dá)式)///</summary>///<param name="strInput">輸入的字符串</param>public void MatchStr(string str){Regex reg = new Regex(@"\bm\S*e\b");MatchCollection mat = reg.Matches(str);foreach (Match item in mat){Debug.Log(item);}}

6-2、替換掉空格的表達(dá)式

項(xiàng)目中,總會遇到模型名字上面有多余的空格,有時候會影響查找,所以下面演示如何去掉多余的空格
代碼如下:

  ///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (去掉多余的空格的表達(dá)式)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_8(string str){Regex reg = new Regex("\\s+");Debug.Log(reg.Replace(str, " "));}

七、完整的測試代碼

代碼如下:

using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;public class Bool_Definition : MonoBehaviour
{void Start(){#region 轉(zhuǎn)義字符測試string temp = "\r\nHello\nWorld.";IsMatch(temp);#endregion#region 字符類測試string temp1 = "Hello World 2024";IsMatch_1(temp1);#endregion#region 定位點(diǎn)測試string temp2 = "Hello World 2024";IsMatch_2(temp2);#endregion#region 限定符測試string temp3 = "Hello World 2024";IsMatch_3(temp3);#endregion#region 校驗(yàn)數(shù)字測試string temp4 = "2024";IsMatch_4(temp4);#endregion#region 校驗(yàn)字符測試string temp5 = "你好,時間,2024";IsMatch_5(temp5);#endregion#region 校驗(yàn)特殊需求測試      IsMatch_6();#endregion#region 匹配字母實(shí)例測試    string temp7 = "make mave move and to it mease";IsMatch_7(temp7);#endregion#region 去掉空格實(shí)例測試    string temp8 = "GOOD     2024";IsMatch_8(temp8);#endregion}///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (轉(zhuǎn)義字符)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch(string strInput){string pattern = "\\r\\n(\\w+)";Match resultBool = Regex.Match(strInput, pattern);Debug.Log(resultBool.Value);}///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng) (字符類)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_1(string strInput){string pattern = "(\\d+)";Match resultBool = Regex.Match(strInput, pattern);Debug.Log(resultBool.Value);}///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng) (定位點(diǎn))///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_2(string strInput){string pattern = "(\\w+)$";Match resultBool = Regex.Match(strInput, pattern);Debug.Log(resultBool.Value);}///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (限定符)///</summary> ///<param name="strInput">輸入的字符串</param>public void IsMatch_3(string strInput){string pattern = "\\w{5}";Match resultBool = Regex.Match(strInput, pattern);Debug.Log(resultBool.Value);}///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (常用的校驗(yàn)數(shù)字表達(dá)式)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_4(string strInput){Regex reg = new Regex(@"^[0-9]*$");bool result = reg.IsMatch(strInput);Debug.Log(result);}///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (常用的校驗(yàn)字符表達(dá)式)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_5(string strInput){Regex reg = new Regex(@"^[\u4E00-\u9FA5A-Za-z0-9]");bool result = reg.IsMatch(strInput);Debug.Log("匹配中文、英文和數(shù)字:" + result);Regex reg2 = new Regex(@"^[A-Za-z0-9]");bool result2 = reg2.IsMatch(strInput);Debug.Log("匹配英文和數(shù)字:" + result2);}///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (常用的校驗(yàn)特殊需求的表達(dá)式)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_6(){Regex reg = new Regex(@"[a-zA-z]+://[^\s]*");bool result = reg.IsMatch("http://www.baidu.com");Debug.Log("匹配網(wǎng)址:" + result);Regex reg2 = new Regex(@"^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$");bool result2 = reg2.IsMatch("13512341234");Debug.Log("匹配手機(jī)號碼:" + result2);}///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (匹配以m開頭,以e結(jié)尾的表達(dá)式)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_7(string str){Regex reg = new Regex(@"\bm\S*e\b");MatchCollection mat = reg.Matches(str);foreach (Match item in mat){Debug.Log(item);}}///<summary>///在輸入的字符串中搜索正則表達(dá)式的匹配項(xiàng)  (去掉多余的空格的表達(dá)式)///</summary>///<param name="strInput">輸入的字符串</param>public void IsMatch_8(string str){Regex reg = new Regex("\\s+");Debug.Log(reg.Replace(str, " "));}}

總結(jié)

以后有更好用的會繼續(xù)補(bǔ)充
不定時更新Unity開發(fā)技巧,覺得有用記得一鍵三連哦。

http://www.risenshineclean.com/news/54004.html

相關(guān)文章:

  • b2b貿(mào)易網(wǎng)站公司推廣渠道
  • 硬盤做網(wǎng)站空間漢中seo培訓(xùn)
  • 武漢網(wǎng)站建設(shè)哪家好電腦培訓(xùn)班附近有嗎
  • pcb設(shè)備網(wǎng)站怎么做適合seo軟件
  • 鄭州高端建站公司中國搜索引擎有哪些
  • 如何建立新聞網(wǎng)站搜索引擎bing
  • 西安php網(wǎng)站開發(fā)培訓(xùn)班信息流廣告哪個平臺好
  • 網(wǎng)站制作技巧南京百度快速排名優(yōu)化
  • 網(wǎng)站開發(fā)服務(wù)流程廣州seo網(wǎng)絡(luò)營銷培訓(xùn)
  • 購物網(wǎng)站用html怎么做怎么樣做一個自己的網(wǎng)站
  • dede企業(yè)網(wǎng)站模板下載sem和seo的區(qū)別
  • 做外貿(mào)要建什么網(wǎng)站百度收錄批量查詢
  • 做美國市場哪個網(wǎng)站好百度搜索競價
  • 陜西省教育類網(wǎng)站前置審批新聞危機(jī)公關(guān)
  • 重慶找做墩子網(wǎng)站新冠病毒最新消息
  • 做公司網(wǎng)站計(jì)入什么會計(jì)科目網(wǎng)絡(luò)seo優(yōu)化推廣
  • 建站公司沒前端網(wǎng)站推廣app下載
  • 微信網(wǎng)站開發(fā)有中院管轄呢網(wǎng)站制作公司網(wǎng)站
  • 企業(yè)網(wǎng)站服務(wù)器建設(shè)方法最好的網(wǎng)站推廣軟件
  • 網(wǎng)站制作網(wǎng)址網(wǎng)絡(luò)推廣方法怎么做
  • 南京網(wǎng)站建設(shè)公司 w搜索引擎優(yōu)化專員
  • 國外網(wǎng)站做色情主播app拉新推廣接單平臺
  • 福州綜合網(wǎng)站建設(shè)慧生活798app下載
  • 金華網(wǎng)站建設(shè)哪里好百度權(quán)重域名
  • 公司網(wǎng)站建設(shè)怎么計(jì)費(fèi)網(wǎng)絡(luò)推廣員工作好做嗎
  • alexa排名全球前50網(wǎng)站排名優(yōu)化方案
  • 交河做網(wǎng)站價格windows優(yōu)化大師可靠嗎
  • 如何承接設(shè)計(jì)網(wǎng)站建設(shè)傳媒網(wǎng)站
  • 諸城做網(wǎng)站的公司php視頻轉(zhuǎn)碼
  • 在線直播網(wǎng)站怎么做人民網(wǎng)輿情數(shù)據(jù)中心官網(wǎng)