Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-30-2008, 06:47 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 880
Nicholas Jordan is on a distinguished road
[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.
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:
Code:
replace localhost:8084 gets replace belvcomp.com gets
Goin dizzy, cannot see the screen anymore. May have missed something.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-30-2008, 08:23 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 533
fishtoprecords is on a distinguished road
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
Code:
nick.com www.nick.com
equally well?

Last edited by fishtoprecords : 07-30-2008 at 08:26 AM. Reason: weird auto expand
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-30-2008, 06:56 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
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.
Quote:
if you have one line of input/sample and the output, followed by the second input/sample and output.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-30-2008, 07:10 PM
Member
 
Join Date: Jul 2008
Posts: 31
skaspersen is on a distinguished road
google "regex test harness" and follow that java turtorial. The class has helped me many a times when trying to get a regex right
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-30-2008, 08:21 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 880
Nicholas Jordan is on a distinguished road
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:
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
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)
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Last edited by Nicholas Jordan : 07-30-2008 at 09:38 PM.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-30-2008, 08:34 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
No code, just two columns with input/before and output/after examples. I'll come up with the patterns to do the transforms.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-30-2008, 11:52 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 880
Nicholas Jordan is on a distinguished road
Samples for Norm
try this:
Regular Expression Editor

message edit: It appears I have been successful:

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
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Last edited by Nicholas Jordan : 07-31-2008 at 09:26 AM. Reason: success
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 07-31-2008, 12:02 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
Guess you missed my point.
Good luck on your project.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pls helpme in replacing set and get methods with List shobha2k8 New To Java 1 07-16-2008 11:25 AM
replacing array values Jononomous New To Java 1 05-22-2008 05:27 PM
replacing last comma in a string with the word "or" wprjr New To Java 1 05-07-2008 03:19 AM
Replacing at an index bugger New To Java 2 01-29-2008 08:33 AM
splitting string and replacing itsme New To Java 1 12-11-2007 05:08 PM


All times are GMT +3. The time now is 08:03 AM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org