Carey Brown

Saloon Keeper
+ Follow
since Nov 19, 2001
Carey likes ...
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
Forum Moderator
Carey Brown currently moderates these forums:
Cows and Likes
Cows
Total received
58
In last 30 days
1
Total given
2
Likes
Total received
1107
Received in last 30 days
17
Total given
137
Given in last 30 days
2
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Carey Brown

I was trying to nudge you in the direction of using an object oriented approach. You were proceeding down a path of redundant, cut-n-paste code, which, while it would work, is not object oriented. One feature of object oriented design is encapsulation. As an example, Group encapsulates the finding and printing so that the code needn't be duplicated for each regex. The side effect of this is that "Group" is now shared among all patterns and any changes to Group need to be done in a way that extends to all regex's. In your case you would need to pass in an additional argument for a format to be used to print.

It seems that you might not be ready for this yet. I was hoping that by giving you an example that you might have been able to learn from it.

So, back to procedural coding. I suggest that you put this code aside and start over. You can reuse, of course, the REGEX_#'s that you created and have now debugged. Remember that debugging was a major goal at the time. Forget using Group for now, but I do recommend creating a separate method for each regex. There will be some cut-n-paste redundancy between them but that is the price you pay.
14 hours ago
You've converted the document to a String and that into a byte array. Now you need to reverse the process. The String class has a way to convert a byte array to a String. You'd have to research how to convert the String to a document.
16 hours ago
You need a different print format for each regex, not all of them have a group named 'info'.
16 hours ago

Knute Snortum wrote:It looks like you've forgotten to set REGEX_1 etc. to your regex string.

20 hours ago

Junilu Lacar wrote:If I understand the program correctly, it looks like it's trying to map numbers that are multiples of other numbers. Lines 24-27 basically prints out any number that isn't mapped. Seems to me just a more inefficient variation of the Sieve of Eratosthenes

It is the Sieve but starting at 'n'. Could be optimized by making divisible by 2 a special case.
1 day ago
I tried it in Eclipse and it didn't give me any output. Then I inserted a  new-line for every 10 numbers and everything magically appeared.

Interesting algorithm, where did you get it? I compared it to a highly optimized Sieve program that I have and yours was fast but only for the given range. I tried to set the range to match my 2 --> N algorithm and I couldn't get a speed because the Map caused a stack overflow. I may try to implement a class to encapsulate that without causing an overflow. I also noticed the algorithm could be significantly improved by not setting the map for the same even numbers over and over.
1 day ago
It would be helpful to use meaningful variable names for t, n, and m. And perhaps a prompt to the user as to what the program is expecting.
1 day ago
Try enclosing the main body in a try/catch block and print the exception stack trace. Always post the complete error message here as text, not a screen snapshot or a link.
1 day ago

Babi Astimal Astimal wrote:can you explain the use of breck in your code ?

The loop tries each regex in order. When you find a regex that matches then none of the remaining regexs can possibly match so there's no point in checking them. Break causes loop to abort because we already found one.
3 days ago

Campbell Ritchie wrote:If you think that is what the question means, Carey, it means I have completely misunderstood it. Sorry

The question is slightly vague so I was just presenting an alternative that didn't involve making a string.
3 days ago

wayne brandon wrote:Am I correct in saying that you can only return the characters at index 0 and 6 if they being added to a String in the return?


3 days ago
  • Please shorten your lines before posting them. Long lines are difficult to read on narrower screens.
  • You were missing group "ti".
  • You don't need non-capturing groups because you only care about the named groups.
  • If you want to collect all INFOP groups together make a list of all found groups and then provide logic to pick the groups you want to print to a txt file.


  • 3 days ago
    Missing 'break'.
    4 days ago

    4 days ago
    Don't remember if this involved a Maven plugin or not, but I have used Maven on some projects to create a "jar with dependencies" jar file. The created jar file has all the byte code for any directly or indirectly accessed classes.
    5 days ago