replaceall

String replaceAll() vs. Matcher replaceAll() (Performance differences)

Pretty simple question, but this is coming from a C/C++ person getting into the intricacies of Java. I understand I can fire up jUnit and a few performance tests of my own to get an answer; but I'm just wondering if this is out there. Are there known difference(s) between String.replaceAll() and Matcher.replaceAll() (On a Matcher Objec...

using java regex how can I replace all when pattern contains left parenthesis

I have a string that looks like this: "mynum(1234) and mynum( 123) and mynum ( 12345 ) and lastly mynum(#123)" I want to insert a "#" in front of the numbers in parenthesis so I have: "mynum(#1234) and mynum( #123) and mynum ( #12345 ) and lastly mynum(#123)" How can I do this? Using regex pattern matcher and a replaceAll chokes on ...

Java: str.replaceAll() not working

I'm trying to cleanse one String from another. before = before.replaceAll(Constants.GENE_START_SEQUENCE, ""); And yet, the following assertion sometimes fails: assert before.indexOf(Constants.GENE_START_SEQUENCE) == -1 : before; This is what the assert spits out: IIAOOOCOAAAOCCIOOOACAIAOACICOOIAIOOICIIOIIOICOICCCOOAOICOCOOIIOOAOAA...

Regarding Java String Manipulation

I have the string "MO""RET" gets stored in items[1] array after the split command. After it get's stored I do a replaceall on this string and it replaces all the double quotes. But I want it to be stored as MO"RET. How do i do it. In the csv file from which i process using split command Double quotes within the contents of a Text field a...

groovy: how to replaceAll ')' with ' '

i tried this: def str1="good stuff 1)" def str2 = str1.replaceAll('\)',' ') but i got this: Exception org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Script11.groovy: 3: unexpected char: '\' @ line 3, column 29. 1 error at org.codehaus.groovy.control.ErrorCollector(failIfErrors:296) question: how to d...

replace \n and \r\n with <br /> in java

This has been asked several times for several languages but I can't get it to work. I have a string like this String str = "This is a string.\nThis is a long string."; And I'm trying to replace the \n with <br /> using str = str.replaceAll("(\r\n|\n)", "<br />"); but the \n is not getting replaced. I tried to use this RegEx Tool to...

Java replaceAll with regular expression

I have a text like this: ...<span>my name is bob and I live in </p><p>America</span>... I would replace this text in ...<span>my name is bob and I live in </span></p><p><span>America</span>... I know the replace() function, but I don't know well regular expressions, how it's possible to do this? Keep in mind that is possible to h...

How the Java equivalent to this preg_replace?

<?php $str = "word <a href=\"word\">word</word>word word"; $str = preg_replace("/word(?!([^<]+)?>)/i","repl",$str); echo $str; # repl <word word="word">repl</word> ?> source: http://pureform.wordpress.com/2008/01/04/matching-a-word-characters-outside-of-html-tags/ Unfortunality my project needs a semantic libs avaliabl...

How optimize this regex?

My tool gets a plain text and gradually generates the "tags" by replacing a terms from text in tags. Due to existence of some compound terms, the only way (i think) is use ReplaceAll regex. Thanks to the friends of stackoverflow, in my last question i got a excellent regex to my app, but after a tests, emerged a new need: "A regex ...

java String.replaceAll regex question

I have a string that contains the following text String my_string = "hello world. it's cold out brrrrrr! br br"; I'd like to replace each isolated br with <br /> The issue is that I'd like to avoid converting the string to "hello world. it's cold out <br />rrrrr! <br /> <br />"; What I'd like to do is convert the string (using ...