replaceall « Operation « Java Regex Q&A

Home
Java Regex Q&A
1.Development
2.find
3.group
4.Match
5.matcher
6.number
7.Operation
8.parse
9.Pattern
10.replace
11.validation
12.word
Java Regex Q&A » Operation » replaceall 

1. Java String.replaceAll regex    stackoverflow.com

What is the regex to strip the MY-CORP\ part of na inputed string like MY-CORP\My.Name with the java String.replaceAll method so I can get only the My.Name part? I tried

public static String ...

2. Why String.replaceAll() don't work on this String?    stackoverflow.com

    //This source is a line read from a file 
    String src = "23570006,music,**,wu(),1,exam,\"Monday9,10(H2-301)\",1-10,score,";

    //This sohuld be from a matcher.group() when ...

3. comma in regex in String.replaceAll() method?    stackoverflow.com

My code tries to replace "," with "/" in a string. Should I escape "," in the regex string? Both of the two code snippets generated the same results, so I ...

4. Java replaceAll with regular expression    stackoverflow.com

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() ...

5. How optimize this regex?    stackoverflow.com

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) ...

6. java String.replaceAll regex question    stackoverflow.com

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 ...

7. Java replaceAll regex using found instances    stackoverflow.com

I was looking for a way to replace instances of [number][char] or [char][number] like it occurs in mathematical expressions (e.g. 4x + 20y) with [number]*[char] or [char]*[number], I have two problems with that

  • How ...

8. Java replaceAll() & split() irregularities    stackoverflow.com

I know, I know, now I have two problems 'n all that, but regex here means I don't have to write two complicated loops. Instead, I have a regex that only ...

9. Java regex replaceAll multiline    stackoverflow.com

I have a problem with the replaceAll for a multiline string:

String regex = "\\s*/\\*.*\\*/";
String testWorks = " /** this should be replaced **/ just text";
String testIllegal = " /** this should ...

10. Java ReplaceAll Problem    stackoverflow.com

I am writing a program to solve postfix problems. I am not needing help with the algorithm as I already know it. But I have stumbled across a problem with the ...

11. java String.replaceAll without regex    stackoverflow.com

I'd like to replace all instances of a substring in a string but String.replaceAll() only accepts a pattern. The string that I have came from a previous match. Is it possible ...

12. Java replaceAll with newline symbol    stackoverflow.com

the newline symbol \n is causing me a bit of trouble when i try to detect and replace it: This works fine:

String x = "Bob was a bob \\n";
String y = x.replaceAll("was", ...

13. Java Regex: using functions/methos in String.replaceAll()    stackoverflow.com

I am trying to convert an RPN-equation into a string that matches tigcc rules. There numbers must have the number of chars in front of them and a tag for positive ...

14. Prepending string using replaceAll and regex    stackoverflow.com

I can't figure out how to create regular expression using positive lookahead. The idea is to prepend two character string to every two character in a long string. i.e.

"090909" => "XX09XX09XX09"
This ...

15. Java: Understanding the String replaceAll() method    stackoverflow.com

I'm looking to figure out the answer to this problem here. First off,

blah[abc] = blah[abc].replaceAll("(.*) (.*)", "$2, $1");
Can someone explain to me what the (.*), $2 and $1 are? Secondly, when I nest ...

16. ReplaceAll java throws exception    stackoverflow.com

why does this code throw an exception?

file = file.replaceAll(Pattern.quote("/"),File.separator);
Message: String index out of range: 1
File: null Class: java.lang.String Methode: charAt Line: -1
File: null Class: java.util.regex.Matcher Methode: appendReplacement Line: -1
File: null Class: ...

17. String.replaceAll() with regexp problem    stackoverflow.com

i have a java code where i select a record from db using Spring Hibernate native query and tried to strip HTML tags from a text.

  String sql = ...

18. Escaping double-slashes with regular expressions in Java    stackoverflow.com

I have this unit test:

public void testDeEscapeResponse() {
    final String[] inputs = new String[] {"peque\\\\u0f1o", "peque\\u0f1o"};
    final String[] expected = new String[] {"peque\\u0f1o", "peque\\u0f1o"};
  ...

19. Input Sanitizing to not break JSON syntax    stackoverflow.com

So, in a nutshell I'm trying to create a regex that I can use in a java program that is about to submit a JSON object to my php server. myString.replaceAll(myRegexString,""); My question ...

20. replaceAll and beginning of line (java)    stackoverflow.com

I would like to use String's replaceAll function to delete any char that is not in a given set. I tried

x = x.replaceAll("^[A-Za-z]", "");
However this is not working because when placed ...

21. Could you please help on a replaceAll Java with regex example below    stackoverflow.com

Pattern p=Pattern.compile("( see the example pattern )");
Matcher matcher=p.matcher(text);
String result=matcher.replaceAll("");
i.e.
  • 2009-10-05T13:44:34+0000
  • 2011-03-13T23:59:24+0000
  • 2010-10-11-09T15:39:37+0000
  • 2009-10-05T13:44:34+0000

22. Java regex replaceAll not working    stackoverflow.com

regex not working as wanted Code example:

widgetCSS = "#widgetpuffimg{width:100%;position:relative;display:block;background:url(/images/small-banner/Dog-Activity-BXP135285s.jpg) no-repeat 50% 0; height:220px;} 

someothertext #widgetpuffimg{width:100%;position:relative;display:block;}"

newWidgetCSS = widgetCSS.replaceAll("#widgetpuffimg\\{(.*?)\\}","");
I want all occurrences in the string that match the pattern "#widgetpuffimg{anycharacters}" to be replaced by ...

23. Regular expression for String.replaceAll    stackoverflow.com

I need a regular expression that can be used with replaceAll method of String class to replace all instance of * with .* except for one that has trailing \ i.e. conversion ...

24. String ReplaceAll method not working    stackoverflow.com

I'm using this method to parse out plain text URLs in some HTML and make them links

private String fixLinks(String body) {
    String regex = "^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
    ...

25. String ReplaceAll regex problem    coderanch.com

I've extracted some HTML data into a string. I now want to remove all tags and the data between them. For example: abc(AM def should become: abcdef I've tried to use replaceAll but I'm not very knowledgeable with regex patterns. So far I've tried ".*" but that does not work. Why? Because I have many ...

26. Building this regular expression with replaceAll    coderanch.com

Hi all, I'm having problems in building a regular expression that transforms negative numbers. I need to put a single quote around negative numbers. That is: String formula = "SWITCH: case 1: method1() case -1: exit()"; should become: "SWITCH: case 1: method1() case '-1': exit()"; Does anybody know how to obtain it with replaceAll() ? Thanks a lot Francesco

27. Problem escaping single quotes using regex with replaceAll()    coderanch.com

Hi All, Here's the issue. I have strings coming in that may have single quotes in them. I need to print these strings out onto a page as parameters to particular javascript functions. If I have onclick with the function call wrapped in double quotes and the parameter wrapped in single quotes I need to have this string escaped (i.e. the ...

29. Regular Expressions and String.replaceAll()    java-forums.org

import java.io.*; public class IO { public String strIn() { BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); String input = null; try { input = console.readLine(); } catch (IOException e) { input = "<" + e + ">"; } return input; } public double numIn() { BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); String input = null; try { input = console.readLine(); } ...

30. replaceAll and Regex help    forums.oracle.com

31. replaceAll / regexp / escaping a string    forums.oracle.com

Hi, I have a question about escaping a string for use with replaceAll. My objective is to replace all instances of string1 with string2 so I have been doing so using replaceAll. This works well however with it relying on regexp's I have some questions about escaping. I want to, for example, replace [%PARAM%] with '100%' however this starts to get ...

32. replaceAll regular expression    forums.oracle.com

33. regex, String.replaceAll, ...    forums.oracle.com

hi guys well, im kinda confused since im new to java anymore.. but i can bring that stuff to work.. i want to replace a ' with a \' - sounds simple.. but it isnt.. i tried tons of possibilities - but none worked.. can someone send me a sourcesnippet using String.replaceAll(String,String)? thx

34. RegEx replaceAll question    forums.oracle.com

36. replaceAll(Regex, Function($1))    forums.oracle.com

37. ReplaceAll REGEX Help!    forums.oracle.com

38. Regex replaceAll question    forums.oracle.com

I am using replaceAll to replace a bunch of "tags" with content for this bit of software that I am porting (from something else) that creates documents (in the end) by populating templates with data. Here's my problem. The "tags" are all okay (not giving any regex content) but some of the data is. Because at first now I hit data ...

39. replaceAll using regular expression    forums.oracle.com

If we're assuming that he wants to replace a specified String that occurs somewhere in between | and |, then prometheuzz's reply 4 works, as long as the String is regex-escaped, but it probably can't have | in it. As far as using regexs goes, I consider them write once, read never. Trying to maintain a regex that's more that a ...

40. Regular expressions in String.replaceAll()    forums.oracle.com

Hi, I'm trying to implement automatic contextual links on a site. What I want is to parse a text (containing HTML tags) and replace every occurence of a word by a link. e.g., the text: "This is a test text for replacement". would be replaced by "This is a test text for replacement". Now, obviously I don't want to just do ...

41. Regular expressions in String.replaceAll()    forums.oracle.com

Hi, I'm trying to implement automatic contextual links on a site. What I want is to parse a text (containing HTML tags) and replace every occurence of a word by a link. e.g., the text: "This is a test text for replacement". would be replaced by "This is a test text for replacement". Now, obviously I don't want to just do ...

42. regex:replaceAll()    forums.oracle.com

43. Using string.replaceAll() throws java.util.regex.PatternSyntaxException    forums.oracle.com

Running the above results in the following output: /build/wheeeeeee java.util.regex.PatternSyntaxException: Unknown character category {r} near index 2 \production ^ at java.util.regex.Pattern.error(Unknown Source) at java.util.regex.Pattern.familyError(Unknown Source) at java.util.regex.Pattern.retrieveCategoryNode(Unknown Source) at java.util.regex.Pattern.family(Unknown Source) at java.util.regex.Pattern.sequence(Unknown Source) at java.util.regex.Pattern.expr(Unknown Source) at java.util.regex.Pattern.compile(Unknown Source) at java.util.regex.Pattern.(Unknown Source) at java.util.regex.Pattern.compile(Unknown Source) at java.lang.String.replaceFirst(Unknown Source) Exception in thread "main"

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.