Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
579 views
in Technique[技术] by (71.8m points)

c# - How to completely ignore linebreak and tab in RegEx?

Is there any way to completely ignore line break and tab characters etc. in RegEx? For instance, the line break and tab characters could be found anywhere and in any order in the content string.

... [CustomToken  
 Type="User"  
 Property="FirstName" 
 /] ... [CT ...

The is the RegularExpression that I am currently using:

([CustomToken).*?(/])

.NET API

Regex.Matches(string input, string pattern)

Thanks for your suggestion.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you just want that regex to match that input, all you need to do is specify Singleline mode:

Regex.Matches(input, @"[CustomToken).*?(/])", RegexOptions.Singleline);

The dot metacharacter normally matches any character except linefeed ( ). Singleline mode, also known as "dot-matches-all" or "DOTALL" mode, allows it to match linefeeds as well.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...