Results 1 to 8 of 8
  1. #1
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default [SOLVED] regexs not finding or replacing

    I have been at this fourteen hours, maybe someone can spot something. I have thrown away over a hundered lines of code trying to get some traction.

    Purpose of this routine is to replace localhost:0000 with domain.com and back in any occurence in a directory for build deploy versions. I have read the documentation several times, it says replace all replaces all, find() is suppose to find and so on. Nothing is happening.

    I do not have much time with regexes.
    Java Code:
    // Looks for: "localhost:8080"
    Pattern localHost = Pattern.compile(
        "localhost:8080??", Pattern.CASE_INSENSITIVE);//  I tried changing ?? to +
    // Looks for: "localhost:8080"
    Pattern wwwServer = Pattern.compile(
        "wwwServer\\.com??", Pattern.CASE_INSENSITIVE);// tried changing ?? to +
    //.....
    
    String nextLine = LINE_NUMBER_READER.readLine();
    if( nextLine != null )
    {
        // Matchers and replacers
        wwwURL_matcher = wwwServer.matcher(nextLine);
        
        localHost_matcher = localHost.matcher(nextLine);// Looks for: "localhost:8084"
        //
        do
        {
            if(wwwURL_matcher.lookingAt())
            {
                prototypingDebugLog.append("found www site ");//
            }
            if(localHost_matcher.lookingAt())
            {
                prototypingDebugLog.append("found localhost ");//
            }
            String local = wwwURL_matcher.replaceAll("localhost:8084");
            prototypingDebugLog.append(local + NEW_LINE);//
            prototypingDebugLog.append("replace localhost:8080 gets ");//
            //
            String remote = localHost_matcher.replaceAll("belvcomp.com");
            prototypingDebugLog.append(NEW_LINE);//
            prototypingDebugLog.append("replace (server).com gets ");//
            //
            nextLine=LINE_NUMBER_READER.readLine();
        }
        while( nextLine != null);
    runlog shows:
    Java Code:
    replace localhost:8084 gets 
    replace belvcomp.com gets
    Goin dizzy, cannot see the screen anymore. May have missed something.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  2. #2
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Would be easier to follow if you have one line of input/sample and the output, followed by the second input/sample and output.

    Why do you have ?? in the pattern? Are you trying to eat any query string and/or the beginning of the path?


    Do you care about handeling
    Java Code:
    nick.com
    www.nick.com
    equally well?
    Last edited by fishtoprecords; 07-30-2008 at 06:26 AM. Reason: weird auto expand

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Nick,
    I'd like to learn regex and nothing like a live example to work on.
    If you could give me some examples of what you're trying to do, I'll have a go. If you could list about a half dozen example in two columns with before and after values.
    if you have one line of input/sample and the output, followed by the second input/sample and output.

  4. #4
    skaspersen is offline Member
    Join Date
    Jul 2008
    Posts
    31
    Rep Power
    0

    Default

    google "regex test harness" and follow that java turtorial. The class has helped me many a times when trying to get a regex right

  5. #5
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Post major progress this morning

    Quote Originally Posted by skaspersen View Post
    google "regex test harness" and follow that java turtorial. The class has helped me many a times when trying to get a regex right
    I will work that in a moment, I am swamped right now.

    I have a first 100% thanks to: RegEx: online regular expression testing

    Norm, how much code do you want? Try this to start with: RegExLib.com Regular Expression Cheat Sheet (.NET Framework)


    ftr: I was getting dizzy, it was all I could do to to remove all the fully specified package on every variable and 200 character lines with random strings for variable naming + proprietary removal. What I am trying to do is for an exact URL in the forms I am trying to get running in Servlets: Find and replace ( local | remote ) URL prior to doing a build in NetBeans so as to do testing on local then re-build for deploy on www using an exact swapping of host as defined in:
    Java Code:
    URI(String scheme, String host, String path, String fragment)
    Each invocation of the tool provides two source files with dot extensions appended after .java
    Java Code:
    //
    StringBuffer appendDeployExtension= new java.lang.StringBuffer(TestFind_2.this.currentFile.toString());
    appendDeployExtension.append(".ship");
    java.io.BufferedWriter b9544a26263b = new java.io.BufferedWriter(new java.io.FileWriter(appendDeployExtension.toString()));
    //
    StringBuffer appendPrototypeExtension= new java.lang.StringBuffer(TestFind_2.this.currentFile.toString());
    appendPrototypeExtension.append(".proto");
    java.io.BufferedWriter e16f3638c49 = new java.io.BufferedWriter(new java.io.FileWriter(appendPrototypeExtension.toString()));
    leaving the original source file unmodified by doing a LineNumberReader.readline() then doing a BufferedWriter.append to each of the files from the String returned by the Regex's work.

    I would then manually replace the souces in the NetBeans build directory from the shell and launch NetBeans, removing the appropriate file extension. It is telling that the code that NetBeans produces is exactly how I code, the elimination of such things as code folding and sluggish editor forces me to work from a cold-boot having never invoked NetBeans. After NB finishes, I go down to a cold start and do deploy manually to WEB-INF/classes/(app-dir)
    Last edited by Nicholas Jordan; 07-30-2008 at 07:38 PM.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    No code, just two columns with input/before and output/after examples. I'll come up with the patterns to do the transforms.

  7. #7
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default Samples for Norm

    try this:
    Regular Expression Editor

    message edit: It appears I have been successful:

    Java Code:
    Thu Jul 31 00:21:36 CDT 2008
    Kangaroo
    KangarooKeySpec
    Megapode
    RainDoll
    LocalEncryptor
    discardable
    SetRaw
    Storage
    Total lines processed: 2040
    Total files processed: 8
    Last edited by Nicholas Jordan; 07-31-2008 at 07:26 AM. Reason: success
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

Similar Threads

  1. Pls helpme in replacing set and get methods with List
    By shobha2k8 in forum New To Java
    Replies: 1
    Last Post: 07-16-2008, 09:25 AM
  2. replacing array values
    By Jononomous in forum New To Java
    Replies: 1
    Last Post: 05-22-2008, 03:27 PM
  3. Replies: 1
    Last Post: 05-07-2008, 01:19 AM
  4. Replacing at an index
    By bugger in forum New To Java
    Replies: 2
    Last Post: 01-29-2008, 06:33 AM
  5. splitting string and replacing
    By itsme in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 03:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •