locked
pattern matching RRS feed

  • Question

  •  HI

      i have requirement for pattern matching

    for example : string strtext="Len(text) abc.string";

    and i have to find the words inside the LEN() and string() using LEN({x}) ({x}).string pattern. any suggestion.


    Wednesday, November 21, 2012 1:44 PM

Answers

  • Sounds like a perfect applciation of Regular Expressions ():

    http://www.regular-expressions.info/dotnet.html

    http://msdn.microsoft.com/en-us/library/ms972966.aspx

    Your RE will probably look something like this:

    @"LEN\([^)]\) string\([^)]*\)"

    When you say "the words inside the LEN() and string()" do you mean to imply that there could be multiple white-space separated words as an argument to Len or String? If yes, that could complicate the RE.


    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer


    Wednesday, November 21, 2012 1:58 PM

All replies

  • Sounds like a perfect applciation of Regular Expressions ():

    http://www.regular-expressions.info/dotnet.html

    http://msdn.microsoft.com/en-us/library/ms972966.aspx

    Your RE will probably look something like this:

    @"LEN\([^)]\) string\([^)]*\)"

    When you say "the words inside the LEN() and string()" do you mean to imply that there could be multiple white-space separated words as an argument to Len or String? If yes, that could complicate the RE.


    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer


    Wednesday, November 21, 2012 1:58 PM
  • Hi Pieter,

      i need a generic syntax for above example.means

    string strtext="Len(text) abc.string";

    patterns : ({x}).string or len({x}) or  string({x}) type={x}

    its should return the value of {x}, so i can add any pattern like this

    Wednesday, November 21, 2012 2:14 PM
  • I am struggling a bit with the language barrier, but if I understand correctly, you may need something more powerful than just a Regular Expression handler. You could take a look at http://irony.codeplex.com/as a simple language scanner/parser that does not require learning separate scanner/parser languages like Lex and Yacc do.

    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer

    Wednesday, November 21, 2012 2:25 PM