Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - pascal-like string literal regular expression -


i'm trying match pascal string literal input following pattern: @"^'([^']|(''))*'$", that's not working. wrong pattern?

public void run() {                  using(streamreader reader = new streamreader(string.empty))     {         var linenumber = 0;         var linecontent = string.empty;          while(null != (linecontent = reader.readline()))         {             linenumber++;              string[] inputwords = new regex(@"\(\*(?:\w|\d)*\*\)").replace(linecontent.trimstart(' '), @" ").split(' ');              foreach(string word in inputwords)             {                 scanner.scan(word);             }          }     } } 

i search input string pascal-comment entry, replace whitespace, split input substrings match them following:

private void initialize() {     matchingtable = new dictionary<tokenunit.tokentype, regex>();      matchingtable[tokenunit.tokentype.identifier] = new regex     (         @"^[_a-za-z]\w*$",         regexoptions.compiled | regexoptions.singleline     );     matchingtable[tokenunit.tokentype.numberliteral] = new regex     (         @"(?:^\d+$)|(?:^\d+\.\d*$)|(?:^\d*\.\d+$)",          regexoptions.compiled | regexoptions.singleline     ); } // ... here comes public tokenunit scan(string input) {                              foreach(keyvaluepair<tokenunit.tokentype, regex> node in this.matchingtable)     {         if(node.value.ismatch(input))         {             return new tokenunit             {                 type = node.key                                     };         }     }     return new tokenunit     {         type = tokenunit.tokentype.unsupported     }; } 

the pattern appears correct, although simplified:

^'(?:[^']+|'')*'$ 

explanation:

^      # match start of string '      # match opening quote (?:    # match either...  [^']+ # 1 or more characters except quote character  |     # or  ''    # 2 quote characters (= escaped quote) )*     # number of times '      # match closing quote $      # match end of string 

this regex fail if input you're checking against contains besides pascal string (say, surrounding whitespace).

so if want use regex find pascal strings within larger text corpus, need remove ^ , $ anchors.

and if want allow double quotes, too, need augment regex:

^(?:'(?:[^']+|'')*'|"(?:[^"]+|"")*")$ 

in c#:

foundmatch = regex.ismatch(subjectstring, "^(?:'(?:[^']+|'')*'|\"(?:[^\"]+|\"\")*\")$"); 

this regex match strings like

'this matches.' 'this too, though ''contains quotes''.' "mixed quotes aren't problem." '' 

it won't match strings like

'the quotes aren't balanced or escaped.' there 'before or after' quotes.     "even whitespace problem." 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -