使用C#正则表达式。问题是如何使用“=”

时间:2022-09-02 09:57:53

I`m parsing SQL query with C# Regex.

我用C#Regex解析SQL查询。

I need also to make my pattern to understand "=", for example:

我还需要让我的模式理解为“=”,例如:

string pattern = @"...something...(where)\s\w*\s*(order by)*...something else...";

string pattern = @“...... something ...(where)\ s \ w * \ s *(order by)* ...其他......”;

the following query should match my pattern:

以下查询应与我的模式匹配:

select fieldslist from mytable where fieldvalue=someint order by specialfield

从mytable中选择fieldslist,其中fieldvalue = someint order by specialfield

how can I change the interval of char (I mean "\w*") to make pattern understand my SELECT correctly?

如何更改char的间隔(我的意思是“\ w *”)以使模式正确理解我的SELECT?

1 个解决方案

#1


3  

Use a character class instead of \w

使用字符类而不是\ w

    \w = [A-Za-z0-9_] 

(that is, from A to Z, from a to z from 0 to 9 plus _)

(即,从A到Z,从a到z从0到9加_)

Just add any additional character you want:

只需添加您想要的任何其他角色:

    [A-Za-z0-9_=] 

    string pattern = @"...something...(where)\s[A-Za-z0-9_=]*\s*...";

#1


3  

Use a character class instead of \w

使用字符类而不是\ w

    \w = [A-Za-z0-9_] 

(that is, from A to Z, from a to z from 0 to 9 plus _)

(即,从A到Z,从a到z从0到9加_)

Just add any additional character you want:

只需添加您想要的任何其他角色:

    [A-Za-z0-9_=] 

    string pattern = @"...something...(where)\s[A-Za-z0-9_=]*\s*...";