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 ...
|
//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 ...
|
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 ... |
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() ... |
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) ... |
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 ... |
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
|
|
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 ... |
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 ...
|
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 ... |
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 ... |
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", ...
|
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 ... |
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 ... |
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 ... |
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: ... |
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 = ...
|
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"};
...
|
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 ... |
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 ... |
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
|
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 ... |
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 ... |
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+&@#/%=~_|]";
...
|
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 ... |
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 |
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 ... |
|
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(); } ... |
|
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 ... |
|
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 |
|
|
|
|
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 ... |
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 ... |
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 ... |
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 ... |
|
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" |