Does Java have a built-in way to escape arbitrary text so that it can be included in a regular expression? For example, if my users enter "$5", I'd like to match ... |
In Java, suppose I have a String variable S, and I want to search for it inside of another String T, like so:
if (T.matches(S)) ...
(note: the above line ... |
I need to write a regular expression that finds javascript files that match
<anypath><slash>js<slash><anything>.js
For example, it should work for both :
- c:\mysite\js\common.js (Windows)
- /var/www/mysite/js/common.js (UNIX)
The problem is that the file separator in ... |
I'm working on a solution to a previous question, as best as I can, using regular expressions. My pattern is
"\d{4}\w{3}(0[1-9]|[12][0-9]|3[01])([01][0-9]|2[0-3])([0-5][0-9]){2}"
According to NetBeans, I have two illegal escape characters. I'm ... |
i have a string value that i have to insert in mysql database. and i have to escape some literal like (' , " ,% ,) in this string so how ... |
Sorry if this has been asked, my search brought up many off topic posts.
I'm trying to convert wildcards from a user defined search string (wildcard is "*") to postgresql like wildcard ... |
Hi
I have an html based text (with html tags), I want to find words that occur within angle brackets and replace the brackets with < and > or even when angle ... |
|
I'm working on a simply password strength checker and i can not success applying regular expressions. In different resources different kinds of regular expressions are defined.
i also find javascript regular expressions ... |
My HTML looks like:
<td class="price" valign="top"><font color= "blue"> $ 5.93 </font></td>
I tried:
String result = "";
Pattern p = Pattern.compile("\"blue\"> $ (.*) </font></td>");
...
|
I need to strip out a few invalid characters from a string and wrote the following code part of a StringUtil library:
public static String removeBlockedCharacters(String data) {
if ...
|
String to be split
abc:def:ghi\:klm:nop
String should be split based on ":"
"\" is escape character. So "\:" should not be treated as token.
split(":") gives
[abc]
[def]
[ghi\]
[klm]
[nop]
Required output is array of string
[abc]
[def]
[ghi\:klm]
[nop]
How can the \: ... |
I have a complex regex I want to apply. Here is my pattern:
/(?:^|\s|[\.(\+\-\,])(?:\$?)\$((?:[0-9]+(?=[a-z])|(?![0-9\.\:\_\-]))(?:[a-z0-9]|[\_\.\-\:](?![\.\_\.\-\:]))*[a-z0-9]+)/i
How can I declare this as a String and make sure everything is escaped?
|
Is there a way to escape ( or protect ) special characters in a regular expression?
What I would like to do is to create a simple regex tester:
import java.util.regex.*;
class ...
|
I'm trying to perform some super simple parsing o log files, so I'm using String.split method like this:
String [] parts = input.split(",");
And works great for input like:
a,b,c
Or
type=simple, output=Hello, repeat=true
Just to ... |
i have this little class to make a multiple replace on a string:
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
public class MultipleReplace {
public static void main(String[] args) {
...
|
A silly question, I am not sure what is wrong in the following javafx regex syntax. Netbeans complains illegal escape character in whole of this regex string,
var pattern:String = "(\/S*)(ftp|http|https):\/\/(\w+:\{0,1\}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?";
Any help ... |
I am trying to write regexp for matching token embedded between two curly braces. For example if buffer Hello {World}, I want to get "World" token out of String. When I ... |
I'm trying to break up an array I got through an API on a site, which Java has retrieved as a String. Whenever I run the following code:
String[] ex = ...
|
Ie how do you do this?
String string = "Sample string with ${title} to be inserted.";
string.replaceAll("${title}", title);
All of the following results in an error:
string.replaceAll("\\${title}", title);
string.replaceAll("\\\\${title}", title);
string.replaceAll("\\\\$\\{title\\}", title);
And more, nothing seems to work, ... |
I'm trying to use the following regex in java, that's supposed to match any 'lang="2-char-lang-name"':
String lang = "lang=\"" + L.detectLang(inputText) +"\"";
shovel.replaceFirst("lang=\"[..]\"", lang);
I know that a single slash would be interpreted by ... |
i'm trying to control if a password contain at least one one lower case letter, one upper case letter, one digit and one special character.
i'm trying this:
if(!password.matches("(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])")){
...
|
I'm trying to match user input with wildcards that are simpler than the java regex syntax. Say there's a wildcard A. The user would then enter the input string:
this ( is ... |
I have this line of code to remove some punctuation:
str.replaceAll("[\\-\\!\\?\\.\\,\\;\\:\\\"\\']", "");
I don't know if all the chars in this regex need to be escaped, but I escaped only for safety.
Is there ... |
I want to split a String in Java on * using the split method. Here is the code:
String str = "abc*def";
String temp[] = str.split("*");
System.out.println(temp[0]);
But this program gives me the following error:
Exception ...
|
I use this code:
static Pattern escaper = Pattern.compile("([^a-zA-z0-9])");
public static String escapeRE(String str) {
return escaper.matcher(str).replaceAll("\\\\$1");
}
It works pretty, until I don't use this string: "[". I looked in the ... |
I'm trying to split a string by single quotes, but taking into account that a repeated single quote represents a escaped quote. So for example the following string
String ss ="aaa''bbb'ccc''ddd'eee";
would be ... |
First of all I have to apologize for my poor English, Please let me explain my case,
Assume that I have 2 text boxes for a user to input. On the server ... |
I'm trying to determine whether or not a expression passed into my Expressions class has an operator. Either +-*/^ for add, subtract, multiply, divide, and exponent respectively.
What is wrong with ... |
I need to escape characters like ^, ., [, ], + and \ (tabs and newlines won't be an issue), while leaving others like * and ?.
EDIT = More specifically, I ... |
question related to this
I have a string
a\;b\\;c;d
which in Java looks like
String s = "a\\;b\\\\;c;d"
I need to split it by semicolon with following rules:
- If semicolon is preceded by backslash, it ...
|
I am attempting to replace the first occurrence of the string "[]" in another string:
aString.replaceFirst("[]", "blah");
I get the error:
java.util.regex.PatternSyntaxException: Unclosed character class near index 1 []
[ and ] are obviously ... |
How can I build a regex example that can escape single quote and backslash in a given string for example using java?
input
an'ish&nath$
...
|
I am trying to read a file and hence I am splitting the fields when I receive ',' comma separator . However some fields have ',' in them but they are ... |
I've read the manual, and at the end there was an exercise:
Use a backreference to write an expression that will match a person's name only if that ... |
Hey all, I needed a little help writing a function in java that does the follow for espacing, I want to use regular expressions, I need the following characters to be replaced by a ~ The special characters are replaced as follows: 1. Newline, backspace, Control-M, carriage return, vertical tab characters are each replaced with "~" 2. Double quotes (") are ... |
Hi Is there a method in Java that is equivalent to Perl's "quotemeta"? Basically I get a String input from user, and will remove them from a particular file. The problem is, the String.replaceAll accepts only regex as argument, and hence I have to supress/escape all the special characters like "(", ")", "*" etc.! Thats why I am looking for a ... |
|
|
|
|
I consulted the DateFormat.setLenient(boolean) Javadoc to find out what it does, and it says it controls whether or not the parser may use heuristics to interpret inputs that don't precisely match the object's format. Can someone give me an explanation of heuristics, as they might apply to SimpleDateFormat? Does this mean that if the format was similar the parser might figure ... |
|
|
Hi, I'm trying to use the RegEx method of the String class to match a value. The trouble is the String value I'm trying to match are periods, which are as you know the predefined "any" character for matching. http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html How do I successfully escape this so it will hunt for a period? I assumed I could escape it with the ... |
|
|