Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Handling inconsistent whitespace

Last post 02-03-2010, 5:47 PM by Aussie Susan. 5 replies.
Sort Posts: Previous Next
  •  02-02-2010, 2:23 PM 59190

    Handling inconsistent whitespace

    I am working on PowerBuilder code that way too many people worked on ahead of me. There are numerous coding styles at play here which is making searching very difficult. For example, I am  trying to find all occurences of assignments to a particular object but in some cases the equal sign is separated by a single space on either side and other cases a TAB or multiple tabs to the left or to the right or both. I am using a text editor to evaluate the code and performthe parsing and searching since PowerBuilder sucks.

    I am not sure if the TAB formatting is going to show up in my examples below due to html space formatting, so i added text comments to specify

    il_row = IDw_Master_Control.GetSelectedRow(0)  // single space on each side of equal sign

    ldb_auth_nbr   = IDw_Master_Control   // this one has a TAB between left variable and equal sign

    il_row = IDw_Master_Control // this one has a TAB on each side of the equal sign

    il_row = IDw_Master_Control.  // this one has a TAB tto the right of the equal sign

    1) I want a Regular Expression to return all of these instances.

    2) The 2nd part is to EXCLUDE any lines meeting the above criteria if the word IF is detected on the same line.

    I appreciate any assistance with this.

     

  •  02-02-2010, 2:26 PM 59191 in reply to 59190

    Re: Handling inconsistent whitespace

    Additional Info

    1) the vriable name to the right of the equal is always going to be IDw_Master_Control

    2) the variable name on the left is not always going to be il_row

  •  02-02-2010, 5:07 PM 59194 in reply to 59190

    Re: Handling inconsistent whitespace

    You will need to tell us which "...text editor..." you intend to use as there are many different ones out there which use a variety of regex variants, each with their own set of capabilities and peculiarities.

    In general you can use either the '\s*' or '[:spaces:]*' patterns to match generic whitespace (includes the space and tab characters plus some others). The use of the '*' quantifier mean that it will match 0 or more instances of any whitespace character and so this should match all of the cases you mention.

    As for detecting if there is an "IF" in the same line, this really will depend on the editor/regex you have available. Also it might be useful to know of the "IF" will always appear before and/or after the "=".

    Susan

  •  02-03-2010, 9:46 AM 59239 in reply to 59194

    Re: Handling inconsistent whitespace

    For Text Editors, I currently have Notepad++ and TextCrawler.

    Please let me know if there is a text editor that you recommend.

    I have tried  /s in TextCrawler but must be doing something wrong because it does not find any occurences.

    For Example,

    find all occurrences of assignment from ldb_auth_nbr = IDw_Master_Control

    Since there might be Tabs or Spaces between ldb_auth_nbr and the equal sign, I tried using the following REG EX: 

    ldb_auth_nbr/s= IDw_Master_Control

    I appreciate any assistance.

  •  02-03-2010, 10:27 AM 59240 in reply to 59239

    Re: Handling inconsistent whitespace

    NEVERMIND......

     I figured it out. I missed the *

    thanks !!!

    I would like to know what Editors are recommended.

     

  •  02-03-2010, 5:47 PM 59247 in reply to 59240

    Re: Handling inconsistent whitespace

    I'm not really prepared to answer the "...what Editors are recommended." question as there are so many variables that need to be considered.

    Personally I use NotePad++ a lot but I almost never use the regex search capability within it. (It is based on the Scintilla engine which is targeted to line-by-line matches and uses the POSIX syntax.) If I'm working on a "Word" document (and some other Microsoft-based programs) then I use the VBA VBScript V5.5 regular expression object. If it is a "one off" job, then I've used the Expresso regex test platform and "cut-and-paste"d the result. I've used the .NET platform in some C# programs that "scrape" web pages, PCRE in my Objective-C programs for the Mac, as well as the "RegexLite" library for programs for the iPhone/iPod Touch platforms.

    You really need to understand the environment in which you are working, the number of times you will be using the tool, how manual/automatic the work has to be and so on. Then you can see what tools are available for the combinaiton of circumstances and go from there.

    Susan

View as RSS news feed in XML