簡體   English   中英

特殊字符的正則表達式錯誤

[英]Regex error on special characters

碼:

Regex rx = new Regex(@"A(\S");

foreach (Match match in rx.Matches(strinG))
{
  int ii = match.Index;
  Console.WriteLine(ii);
 }

在運行時給出錯誤,

system argument exception - " A(\S" not enough )' ".

誰能幫助我,如何解決這個問題?

我認為您正在搜索括號,然后反斜杠。

Regex rx = new Regex(@"A\(\S");

嘗試否定匹配:

Pattern regex = Pattern.compile("[^A-Za-z0-9]");

(這將只允許AZ“標准”字母和“標准”數字。

因為您在字符類中沒有空格和下划線,所以我認為遵循正則表達式會更好:

Pattern regex = Pattern.compile("[^\w\s]");

這意味着匹配除[A-Za-z0-9 \\ s_]以外的所有內容

Unicode版本:

Pattern regex = Pattern.compile("[^\p{L}\d\s_]");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM