pattern

Java's String.replace() vs. String.replaceFirst() vs. homebrew

I have a class that is doing a lot of text processing. For each string, which is anywhere from 100->2000 characters long, I am performing 30 different string replacements. Example: string modified; for(int i = 0; i < num_strings; i++){ modified = runReplacements(strs[i]); //do stuff } public runReplacements(String str){ str = str....

Java logback FileAppender file pattern

Hi! I have appender like this. <appender name="Action.FileAppender" class="ch.qos.logback.core.FileAppender"> <file>logs\\${date}\\${thread}.log</file> <encoder> <pattern>%level - %msg%n</pattern> </encoder> </appender> And i want to ${date} and ${thread} be current date and current thread name. How i can do it? ...

Framework design for services

Hi, I am working on this application for which we have to write framework services like reporting, logging, exception handling, security. Since these services are are to be used through the project, i am thinking of exposing the instances of these services through a service container which has reference to the objects of these individual...

LDAP query for returning members of specific groups

Hello all I need to get some users from LDAP, only those that belong to groups whose names begin with a pattern, something like this ((&objectcategory=user)(memberof=cn=**groupNamePattern_***,OU=distribution,DC=xx,DC=com)) I think it needs to do some sort of sub-query, so that it first retrieves the list of groups that match the patt...

Design Pattern for creating a set of data objects

Hi, I'm writing some code to do some stuff and I'm pretty sure its not well designed at the moment but I can't think how I should be refactoring it to make it nicer... The simple summary is that I have some code which goes through some files in a directory structure and different directories contain different content types. I have a li...

Determining the time frame given by a pattern

A date can be formatted using a e.g. SimpleDateFormat(formatPattern, locale). Is it somehow possible to determine the time period (in seconds) that is represented by formatPattern given a date? E.g. if we have Date date = new Date(1286488800); String formatPattern = "yyyy"; is it possible to determine the length of the year (in second...

findPattern() Python Code...not executing correctly?

Hi all, my homework assignment was to: "write a function called findPattern() which accepts two strings as parameters, a filename and a pattern. The function reads in the file specified by the given filename and searches the file’s contents for the given pattern. It then returns the line number and index of the line where the first inst...

ASP.NET MVC - Exception throw?

Hello there, I got a generic repository - should the repository be able to throw exceptions or should I keep it dumb? If I chose to throw exceptions from it, should the service layer then catch it and throw an exception with a more friendly message before it goes to the Controller? Pos1: Repository (Throw) => Service(Catch, Throw new) ...

How to appendReplacement on a Matcher group instead of the whole pattern?

I am using a while(matcher.find()) to loop through all of the matches of a Pattern. For each instance or match of that pattern it finds, I want to replace matcher.group(3) with some new text. This text will be different for each one so I am using matcher.appendReplacement() to rebuild the original string with the new changes as it goes...

How to search same pattern in a string and then take them to array in Java?

For example, The string is: "{{aaa,bbb},{ccc,ddd},{eee,fff}}" I want the program auto split it as a string pattern Pattern is: {{...},{...},{...}} What is the Pattern Matching regex? ...

Undo for a paint program

I am looking into how to write a paint program that supports undo and seeing that, most likely, a command pattern is what I want. Something still escapes me, though, and I'm hoping someone can provide a simple answer or confirmation. Basically, if I am to embody the ability to undo a command, for instance stamping a solid circle on the...

String/Sequence Patterm Mining ! not matching !

Hi , it's a week i'm trying to find an answer for my question , i would appreciate if anyone can help . I've got a list of strings(originally list of sequences which can be viewed as list of strings) and i'd like to find a pattern (which is a string itself) withtin strings of this list , is there any java library which can i use or is t...

How can I test if a filename matching a pattern exists in Perl?

Can I do something like this in Perl? Meaning pattern match on a file name and check whether it exists. if(-e "*.file") { <Do something> } I know the longer solution of asking system to list the files present; read it as a file and then infer whether file exists or not. ...

Get parent bean in prototype bean that gets injected

Hi, I would like to have a Bean and a SubBean like this: @Scope(BeanDefinition.SCOPE_PROTOTYPE) @Component public class SubBean implements ApplicationContextAware{ private Object parent; public void setApplicationContext(ApplicationContext ctx){ this.parent = doSomeMagicToGetMyParent(ctx); } public Object getParent(){ ...

Python: pattern matching for a string

Im trying to check a file line by line for any_string=any_string. It must be that format, no spaces or anything else. The line must contain a string then a "=" and then another string and nothing else. Could someone help me with the syntax in python to find this please? =] pattern='*\S\=\S*' I have this, but im pretty sure its wrong h...

Python Regular Expression Matching: ## ##

Im searching a file line by line for the occurrence of ##random_string##. It works except for the case of multiple #... pattern='##(.*?)##' prog=re.compile(pattern) string='lala ###hey## there' result=prog.search(string) print re.sub(result.group(1), 'FOUND', string) Desired Output: "lala #FOUND there" Instead I get the following...

Python Regular Expression Matching, help please!

Possible Duplicate: Python Regular Expression Matching: ## ## I already asked this question, but let me restate it better... Im searching a file line by line for the occurrence of ##random_string##. It works except for the case of multiple #... pattern='##(.*?)##' prog=re.compile(pattern) string='lala ###hey## there' result=...

Is the activerecord pattern built into Entity Framework 4.0?

In the past I used Sub Sonic which has the activerecord pattern baked into the framework. With Sub Sonic it was very easy to find the "dirty" fields on an update. I now have a need to create an audit table in my application that utilizes Entity Framework 4. Is there a comparable feature in EF 4 that will give me the dirty fields? Thank...

Passing output from one command as argument to another

Hello, I have this for: for i in `ls -1 access.log*`; do tail $i |awk {'print $4'} |cut -d: -f 1 |grep - $i > $i.output; done ls will give access.log, access.log.1, access.log.2 etc. tail will give me the last line of each file, which looks like: 192.168.1.23 - - [08/Oct/2010:14:05:04 +0300] etc. etc. etc awk+cut will extract the dat...

Best way to detect and store path combinations for analysing purpose later

I am searching for ideas/examples on how to store path patterns from users - with the goal of analysing their behaviours and optimizing on "most used path" when we can detect them somehow. Eg. which action do they do after what, so that we later on can check to see if certain actions are done over and over again - therefore developing a...