Regex Searches RRS feed

  • Question

  • I'm trying to take some delphi code and convert it over to C# to test something.  So I copied all of the code and made some search and replaces.  Eventually I get to the point it looks like this.


    Now I have about 50 lines that look like that.  Okay simple!  I'll use a regular expression, right?  So the first thing I want to do is to change it so that it looks like this:

    myObj.myProperty = StrToInt(myQuery.FieldByName('MY_FIELD').Text));

    (Now for those just skimming, I'm making incremental steps to go from Delphi to C#.  So yes, I know that it's not correct at that phase.)

    Easy,  I'll use the expression "(\.\w+)\(" and replace it with "\1 = ".  But then I try it and the IDE says it can't find (\.\w+)\(  Huh?  So I test out (\.\w+) and it finds it.  Okay, so I fire up everyone's favorite regex site regexlib.com  I pasted my regex and my code and it works exactly the way I would expect on regexlib.  This isn't the first time I've struggled with regex searches with Visual Studio (one time it worked however I could only see \0 and not \1).  So is it just broke?  Or am I truly doing something wrong?
    • Moved by CoolDadTxModerator Monday, November 23, 2009 2:56 PM C# related (From:Visual C# IDE)
    • Moved by Chao Kuo Wednesday, November 25, 2009 9:19 AM actually regular expression related (From:Visual C# General)
    Sunday, November 22, 2009 9:51 PM


  • Visual Studio Regex is different then .NET regex. Read our thread "Does VS have a customized Regex"

    What are you trying to find?
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    • Marked as answer by eryang Monday, November 30, 2009 3:07 AM
    Wednesday, November 25, 2009 11:35 PM