String « Development « 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 » Development » String 

1. Negating literal strings in a Java regular expression    stackoverflow.com

So regular expressions seem to match on the longest possible match. For instance:

public static void main(String[] args) {
 String s = "ClarkRalphKentGuyGreenGardnerClarkSupermanKent";
 Pattern p = Pattern.compile("Clark.*Kent", Pattern.CASE_INSENSITIVE);
 Matcher myMatcher = ...

2. Error in Regex for String    stackoverflow.com

I have simple regex

"\".*\""
for me its says select everything between " and ", but it also catches
"text") != -1 || file.indexOf(".exe"
for me its two strings, for regex its one. how can ...

3. Regular Expression (Java)    stackoverflow.com

How do I match the following string?

http://localhost:8080/MenuTest/index.action
The regex should return true if it contains "MenuTest" in the above pattern. Cheers

4. regular expression question    stackoverflow.com

I want to replace the question mark (?) in a string with some other words. What is the regular expression for question mark. For example, I want to replace question mark in ...

5. Raw Strings in Java?    stackoverflow.com

Is there any way to use raw strings in Java (without escape sequences)? (I'm writing a fair amount of regex code and raw strings would make my code immensely more readable) I understand ...

6. Complex Regex getting value from string    stackoverflow.com

Here are some input samples: 1, 2, 3
'a', 'b',    'c'
'a','b','c'
1, 'a', 'b'
Strings have single quotes around them, number don't. In strings, double single quote '' (that's two times ') is the escape ...

7. Similar but not same string sequence    stackoverflow.com

How to match the following sequence:

You wound DUMMY TARGET for 100 points of damage
but not:
You wound DUMMY TARGET with SKILL for 100 points of damage
with the regular expression:
^You wound ([\\w\\s]+)(?!with) for ...

8. How do I write regular expression in Java that takes into account the context of the string I'm looking for?    stackoverflow.com

I want to parse a HTML code and create objects from their text representation in table. I have several columns and I want to save context of certain columns on every ...

9. get particular string using regex in java    stackoverflow.com

i want how to code for get only link from string using regex or anyothers. here the following is java code:

String aas =  "window.open("+"\""+"http://www.example.com/jscript/jex5.htm"+"\""+")"+"\n"+"window.open("+"\""+"http://www.example.com/jscript/jex5.htm"+"\""+")";
how to get the link http://www.example.com/jscript/jex5.htm thanks ...

10. distinguishing a string with flex    stackoverflow.com

I need to tokenize some strings which will be splitted of according to operators like = and !=. I was successful using regex until the string has != operator. In my ...

11. Repeated regular expression    stackoverflow.com

How can I parse a strings like :

name1="val1"    name2="val2"    name3="val3"
I cannot use split(\s+) as it can be name = "val 1". I am doing java but ...

12. Regular expressions in java    stackoverflow.com

String s= "(See <a href=\"/wiki/Grass_fed_beef\" title=\"Grass fed beef\" " +
          "class=\"mw-redirect\">grass fed beef.) They have been used for " +
   ...

13. which delimeter to use while spliting String    stackoverflow.com

I need to split this line string in each line, I need to get the third word(film name) but as you see the delimeter is one big blank character in some ...

14. Java - Regex for the given string    stackoverflow.com

I have the following html code segment:

        <br>
        Date: 2010-06-20,  1:37AM PDT<br>
     ...

15. regex for sepcifying empty string in java    stackoverflow.com

i dont know how to generate a regex that can represent empty string in java

16. Java regular expression for binary string    stackoverflow.com

First, I need to read a binary String from file into memory - how ? To read I tried nio.CharBuffer, and then byte[]. But later I need to get a binary String with ...

17. Regex exclusion behavior    stackoverflow.com

Ok, so I know this question has been asked in different forms several times, but I am having trouble with specific syntax. I have a large string which contains html snippets. ...

18. Why are most string manipulations in Java based on regexp?    stackoverflow.com

In Java there are a bunch of methods that all have to do with manipulating Strings. The simplest example is the String.split("something") method. Now the actual definition of many of those methods is ...

19. String transforming with danger symbols    stackoverflow.com

I have the followings string:

String l = "1. [](a+b)\n2. (-(q)*<>(r))\n3. 00(d)\n4. (a+-b)";
String s = "1. [](a+b)\n2. 00(d)"
First string is a expresions list. Sencond string is a expresions subset of first string, ...

20. regex - including strings: java    stackoverflow.com

I am trying to print out lines from a file which match a particular pattern in java. I am using the Pattern class for doing this. I tried putting the patter as "[harry]" ...

21. Interpreting a Java String    stackoverflow.com

Is there any way to to interpret a string such as "hello\r\n\world" into a string where \r\n has been converted into their actual literal values. The scenario is that a user types ...

22. Simple Java regex not working    stackoverflow.com

I have this regex which is supposed to remove sentence delimiters(. and ?):

sentence = sentence.replaceAll("\\.|\\?$","");
It works fine it converts "I am Java developer." to "I am Java developer" "Am I a Java developer?" ...

23. Can String.indexOf() handle a regular expression as a parameter?    stackoverflow.com

I want to capture the index of a particular String in the input. That String may be enclosed with single quote or double quotes (sometimes no quotes). How can I capture ...

24. StringUtils.isBlank vs. Regexp    stackoverflow.com

So I am looking through some legacy code and finding instance where they do this:

if ((name == null) || (name.matches("\\s*")))
   .. do something
Ignore for the moment that the .matches(..) ...

25. Is there a way to reformat a Java String with regular expressions?    stackoverflow.com

Is there a way to use a Java regex to change a String to be of a certain format? For example, I have an input String containing a date & ...

26. how do I return a float starting at a certain index in a string?    stackoverflow.com

I have a String that has data such as:

String data = "Some information and then value1=17561.2 and then value2=15672.2"
How do I return 17561.2 most efficiently in Java?
String queryString = "value1";

while data.charAt(outputStr.indexOf(queryString)+queryString.length()) ...

27. Regular Expression Program    stackoverflow.com

Hi I have the following text:

SMWABCCA
ABCCAEZZRHM
NABCCAYJG 
XABCCA
ABCCADK
ABCCASKIYRH 
ABCCAKY 
PQABCCAK    
ABCCAKQ 
This method takes a regex in out by the user and SHOULD print out the Strings it applies ...

28. Counting letters in string regex    stackoverflow.com

i have a regex that is half working to count all strings which have odd numbers of X's.

^[^X]*X(X{2}|[^X])*$
This works for nearly all cases:
X
XXX
XAA
AXXX
AAAX etc
but fails when typing something like:
XAXAXA
I need an ...

29. Regex code to transform CSV in strings    stackoverflow.com

I need to write a Java program that transform a CSV file into an array list. A CSV line looks like this: 5/3/2010,"Behrens, Michael Lakeside Apts","Lisle, IL 60532",PD: Noise or domestic reports for ...

30. Regular Expression using User String    stackoverflow.com

I want to convert an incoming user string into a regular expression, and the incoming string may contain whitespace. Is there a way to ignore all whitespace within the string?

31. Regular Expression for Simple Arithmetic String    stackoverflow.com

I'm trying to validate a simple arithmetic expression to insure it fits within the format operand operator operand : 234.34 + 5. I figured out how to validate this easy ...

32. retrieve quoted string using expression language    stackoverflow.com

How to retrieve the quoted value of a property. suppose you have some expression like:

[html:text property="pqrs" styleClass="text" style="width:200px"].
And now i want to retrieve the value of property, styleclass and style ie ...

33. Date regexp and string comparison    stackoverflow.com

  • What is available: a string of unkown format, current date.
  • What can be provided: date regexp
  • What needs to be done: parse string according to specified date regexp and obtain date
Details: I'm actually ...

34. Cutting String by using regexp    stackoverflow.com

I want to cut the string using regexp, but not to cut the regexp part...

String path ="house/room/cabinet/my_books/bought/2011/adventure/Black-Ship01/312 pages/...";
String[] substract=path.split("my_");
path=substract1[1].toString();// books/bought/2011/adventure/Black-Ship01/312 pages/...
String[] substract2=path.split("-Ship.."); //split using -Ship and two random simbols
path=substract[1].toString();

RESULT:   ...

35. Complicated string extraction in java    stackoverflow.com

I am working with a diff library in java that outputs diffs with square brackets around them where multiple diffs of the same type exist and no square brackets for diffs ...

36. regex and java : Generating a regex for a String    stackoverflow.com

Possible Duplicate:
java regex : getting a substring from a string which can vary
Hi, I have an input String as - "Bangalore,Karnataka=India". Sometimes the String can ...

37. Java regex and sed aren't the same...?    stackoverflow.com

Get these strings:

00543515703528
00582124628575
0034911320020
0034911320020
005217721320739
0902345623
067913187056
00543515703528
Apply this exp in java: ^(06700|067|00)([0-9]*). My intention is to remove leading "06700, 067 and 00" from the beggining of the string. It is all cool in java, group 2 always ...

38. Differentiating between slashes in a string using a regular expression    stackoverflow.com

A program that I'm writing (in Java) gets input data made up of three kinds of parts, separated by a slash /. The parts can be one of the following:

  1. A name ...

39. Breaking apart a math equation string    stackoverflow.com

    Pattern pattern = Pattern.compile("([^\\d.]|[\\d.]++)");
    String[] equation =  pattern.split("5+3--323");
    System.out.println(equation.length);
I'm trying to break apart numbers (could be groups) and nonnumbers, in ...

40. Regular Expression Help    stackoverflow.com

I guess this is simple, but I am quite bad at this. I want to replace the following strings: chrome, internet explorer, mozlla, opera or john, jack, jill, bill with ?, ?, ?, ? I need a ...

41. How to check if the string is a regular expression or not    stackoverflow.com

I have a string. How I can check if the string is a regular expression or contains regular expression or it is a normal string?

42. Java string.replaceFirst problems    stackoverflow.com

I'm trying to replace a part of a string. The part contains some special characters:

#L(inches)=24#
I know replaceFirst is regex driven but I can't seem to create a regular expression that matches ...

43. JavaRegEx and complex long string    stackoverflow.com

I'm trying to extract the value from the exception by using regular expression in Java. But the string is too complicated and long (all in one line):

ReturnCode={Val=9002;SubVal=9203;Text=Subscriber not found};Message=Subscriber ...

44. Grabbing an IRC channel in a string with regex    stackoverflow.com

This is my first time posting here, but I've found a lot of answers here, which is awesome. I'm currently trying to grab an IRC channel from a string, and the IRC ...

45. Java regex issues with an exact token    stackoverflow.com

In my Java app I have a "template string", say, "This record's name is : %%%NAME%%%." I want to loop through a list and for each iteration, print out a "customized version" ...

46. Modify large string    stackoverflow.com

I have a large string in the following format -

   <a href="12345.html"><a href="12345.html"><a href="12345.html"><a href="12345.html">
   <a href="12345.html"><a href="12345.html"><a href="12345.html"><a href="12345.html">
Id like to store all occurances of ...

47. Checking for specific strings with regex    stackoverflow.com

I have a list of arbitrary length of Type String, I need to ensure each String element in the list is alphanumerical or numerical with no spaces and special characters such ...

48. Handling multiple string using REGEX in java    stackoverflow.com

I have 5 strings "a,b,c,d,e" in a drop down,i am writing a testcase where i am checking if the user has selected any of the five then insert into DB,currently i ...

49. Regex not operator    stackoverflow.com

Is there an NOT operator in Regexes? Like in that string : "(2001) (asdf) (dasd1123_asd 21.01.2011 zqge)(dzqge) name (20019)" I want to delete all \([0-9a-zA-z _\.\-:]*\) but not the one where it is ...

50. Regex - determine matrix from String    stackoverflow.com

how can I create simple matrix for String that could be contains following combinations

123456 ABC    
123456AB1
123456AB12
123456AB123
123456
for example
if ("\\d + \\d + \\d + \\d + \\d + \\d ...

51. Help in writing a Regular expression for a string    stackoverflow.com

Hi please help me out in getting regular expression for the following requirement I have string type as

String vStr = "Every 1 nature(s) - Universe: (Air,Earth,Water sea,Fire)";
String sStr = "Every 1 form(s) - ...

52. Hundreds of RegEx on one string    stackoverflow.com

In followup to my previous question Hundreds of RegEx on one string I ended up with a regex like following

(section1:|section2:|section3:|section[s]?4:|(special section:|it has:|synonyms:)).*?(?=section1:|section2:|section3:|section[s]?4:|(special section:|it has:|synonyms:)|$)
section section in regex search The regex that ...

53. Regular Expression to check String is valid XHTML or not    stackoverflow.com

Possible Duplicate:
regular expression to check if string is valid XML
I am looking Regular Expression to check String is Valid XHTML or not example
<h2>Legal HTML Entity ...

54. RegularExpression for a String in java    stackoverflow.com

I need to build a regular expression in java which stratify the below criteria

  1. Length of string must be 6-50 characters.
  2. It must not contain spaces.
  3. It can contain letters, numbers and the following ...

55. SoLR Sorting for String Literal - PatternReplaceFilterFactory    stackoverflow.com

What is the regular expression for the following special characters in SOLR.

,~,!,@,Double Quotes,Single Quote,Brackets,? and for every special characters.

My code is:
<fieldType name="Custom_sort" class="solr.TextField" sortMissingFirst="true" sortMissingLast="true" positionIncrementGap="100" autoGeneratePhraseQueries="true">
   ...

56. Java regexp date string    stackoverflow.com

I need help creating a regular expression that will parse the following string :

09-22-11 12:58:40       SEVERE       ...ractBlobAodCommand:104   ...

57. Regex Help for HandBrake DVD Scan    stackoverflow.com

I'm developing in Java and I have a long string of text which contains all the information I need about a particular DVD. (It's the scan output from HandBrakeCLI). I need ...

58. Turn user supplied string into a literal string, to append a pre-defined regular expression    stackoverflow.com

I have a user supplied string, that I then need to turn into a Regular Expression where their string is treated as a literal, then I append a pre-written regular expression ...

59. Regex expression to help count only the zeros in a string    stackoverflow.com

I'm trying to count the number of 0s in a string of numbers. Not exactly just the character 0, but the number zero. e.g. I want to count 0, 0.0, 0.000 ...

60. Need to accept only % symbol as an input string    stackoverflow.com

I want to accept only % symbol(optional) as a string variable with a number, as in input as percentage. E.G, 1000% or 100% or maybe 2000% or plain string input as ...

61. using regexp in java. getting strings around pipes    stackoverflow.com

In a huge way related to finding matches inside pipes using java regexp I tried getting the string inside the pipes but not around. for example, i input this.

|asd|qwe|zxc|||
Using split ...

62. forming correct regular expression in dynamic string    stackoverflow.com

I have a FileInputStream who reads a file which somewhere contains a string subset looking like:

...
    OperatorSpecific(XXX)
    {
       Customer(someContent)
 ...

63. Regular Expression in String    coderanch.com

64. is there a way to get index of the first occurance of a pattern/regex in a string?    coderanch.com

Given a pattern, e.g. with regular expression "\\s/\\*@.+@\\*/\\s", and a string, is there a way to get the index of the first occurrance of this pattern in the string? It seems indexOf() in String class can only deal with concrete str as parameter, rather than a regular expression or a pattern. Thanks,

65. Making strings safe for regex    coderanch.com

Hi guys, Is there a way to make strings safe for regex. What I mean is: We have an application that uses regex to do some pattern finding. However, we don't want anything the user enters to interfere with this pattern finding. So, what's happening is that some of the characters used by the user are creating regex searches (and throwing ...

66. Regular Expressions and String replacements    coderanch.com

I'm looking for ideas for a program that I'm modifying that does an edit function on groups of files. The data is html and the edits are to change the HREF= that are to a server engine as query strings to be changed to local references. For example HREF="thesite/engine.php?id=22&topic=345". I want to change this to HREF="Topic345/22.html". I'm trying to use regex ...

67. Regular Expression in String    coderanch.com

68. regular expressions on Strings    coderanch.com

Hello, Suppose I have String that always looks like this: ,,,,.... I would like to get all the text which starts at the 4th "," from the end till the end. I know how to do it using String manipulations (substring, replace ect) but I am looking for more elegant way using regular expressions. Anyone can suggest a solution? [ December ...

69. regex for hard coded string    coderanch.com

70. String RegEx    coderanch.com

71. String and Regex    coderanch.com

hi, I have a string "Tracking Number|Carrier" in which im looking for regex "|". On windows platform with java 1.5.0_11 im able to successfully match using regex-string as "\\|". But the same regexstirng on same datastring is not working on Linux with java 1.5.0_08 Let me know if this really due to java version and platform mismatch or internally there is ...

72. regex for hard coded string    coderanch.com

73. String.equals() versus regex    coderanch.com

Hi all, I need to compare two Strings. String a = "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"; // constant String b; // b will vary during execution but have the same length and format only with various characters instead of 'x'. I have written: if (!a.equals(b)) ...in my code. I have been advised that this test could be improved upon by using Regex expressions - somehow! ...

74. string extraction using regular expressions    coderanch.com

hello friends . i wanted to read a string from text file "MRN 123456789" . This text is actually obtained from or extracted from a pdf file to text file using pjtext jar file . while extracting to text file it will be in its own format . i have written a code to extract the above number using regular expressions ...

75. regular expression for strings    coderanch.com

Manepalli, I think the best way to write a complex regular expression is to write smaller ones. Can you figure out how to write a regular expression to match: 1) a single letter 2) any number of letters, numbers and underscores 3) At most one dot 4) A 4-32 character string Once you know how to do all of the above, ...

76. Regular expression to take integers out of a string    coderanch.com

Thank you paul for your reply But the regular expression which you gave only takes the integer which is before packets output. But in my case i have to take both the integers before packets input and packets output in one traverse. Hope you understood my problem. final String regex = "([^\\s]*[0-9]*)\\s*packets\\s*input.*"+ "\\s*([^\\s]*[0-9]*)\\s*packets\\s*output"; The above regex is written by me its ...

77. String Extraction using regex    coderanch.com

Hi, I have a multi line status xml out of which i need to extract the status value. ok Failed i cannot parse it as a xml and i have to use a pattern to extract the "ok" or"failed"(or it could be any other error code which i dont know in advance). can some one please help me to extract the ...

78. strings and regular expressions.    coderanch.com

I am given the the following string that I need to process. frame= 71 fps= 0 q=32.0 size= 12kB time=1.93 bitrate= 50.2kbits/s dup=0 drop=69 I need to grab the text after "time=" In perl I remember being able to easily grab the word or words after the matched pattern. Does Java support such a feature? If I split the stirng, "time=XXXX" ...

79. String operations or regex please    java-forums.org

no i think he only wanted the class headline like you originally posted, but i was just curious myself, thanks. what i meant was, so that the program would recognize all forms of H1

i thought that * indicates any character or no character, but i guess thats not correct

80. Regex and String    forums.oracle.com

81. Regex on a String?    forums.oracle.com

82. String Regular Expression Question    forums.oracle.com

83. RegExp against non standard String    forums.oracle.com

84. Regular Expression / String question?    forums.oracle.com

85. Command line style regular expression string parser    forums.oracle.com

Hi people, I am currently working on a program where I need to parse a file (or any input stream) line by line. I then need to parse every line for arguments. Each line is formatted similar to how arguments are passed to the command line. The regular expression needs to split every line by any encountered whitespace, but needs to ...

86. Generation of random strings based on a regular expression    forums.oracle.com

For fairly simple regex-es, something can easily be constructed, but I'm pretty sure there is no such tool that can generate a String from any regex (including look arounds, and what not). The question is asked from time to time at the "Perl monastery" (that's the place the true regex-wizards come together!). Checkout what they have to say about it: [http://www.perlmonks.org/?node_id=284513] ...

87. regular expressions string length    forums.oracle.com

88. String manipulation using Regular expression    forums.oracle.com

Yes, I am working with sort of xml. Yes, solution to this using xslt would also work. I actually tried to create the "Document" object using the string and got some exception. How this can be done? Do I need to place tag? In my case its not possible for me to format this as a proper XML. I ...

89. String and regex    forums.oracle.com

hi, I have a string "Tracking Number|Carrier" in which im looking for regex "|". On windows platform with java 1.5.0_11 im able to successfully match using regex-string as " |". But the same regexstirng on same datastring is not working on Linux with java 1.5.0_08 Let me know if this really due to java version and platform mismatch or internally there ...

90. String combining and regex problem    forums.oracle.com

Hi everybody, I'm having a bit of a hard time figuring out a string problem, and I'd be much obliged if anybody could give me ideas. I have a set of strings like this (all of them are in the same set, they're separated and organized here for clarity): One Two Three One Two Two Three One Six Four ...

91. return regex string    forums.oracle.com

I know how to run an regular expression and return a boolean if the pattern is matched. How do I return the actual string that is matched? e,g The is string is: "fasfasf safas 12345 rgrg" My regex matches 12345 I want to return 12345 as a string rather than a boolean stating the match was sucesfull. Thanks

92. How to create a list of string if a regular expression is given ?    forums.oracle.com

Hi folks, I have a regular expression say abcd[a-z]\\\.[0-9] . ( please ignore one '\') For this string i know that following string matches successfully 1. abca.0 2. abcb.1 3. abcz.9 ......etc n number of combination are possible. is there any algorithm which will create some randomn strings from a regular expression. input to algorithm : some string pattern output to ...

93. Help with Regex for the following string : .jpg,.gif,.bmp    forums.oracle.com

I think matches() tests the entire input against the regex, so you need the leading .* in order for it to match a string that ends with, say, ".jpg", but I believe that find just searches for a match in the substring, in which case you may need to add a "$" to the end of the regex to indicate you ...

94. Change string using regex.    forums.oracle.com

Parsing a date in one format and then displaying it another screams (Simple)DateFormat to me. If this is homework and you specifically have to use a regex, be my guest. If you are solving a real problem, I would look at SimpleDateFormat and define two formats: one that matches the input you expect and one that matches the output you want. ...

95. String and regular expression    forums.oracle.com

96. Regular Expressions and String variables    forums.oracle.com

@sabre150: your note re: CharSequence -- so what you're suggesting is to implement a CharSequence that wraps the file contents, and then use the regexps on the whole thing? I like the idea but it seems like it would only be easy to implement if the file uses a fixed-width character set. Or am I missing something...?

97. String handling...regex    forums.oracle.com

Hi all, could I get your help in getting this problem solved? I have a string "SELECT MAX([score] ) , SUM([marks] ) from MATH" The column names, score and marks may change and even the number of aggregations used may change. Like more MAX MIN and SUM operations may be added. Can I get the list of column names into a ...

98. substitute Values within a String by using java.util.regex    forums.oracle.com

Hi, Ive try to change the following value "30.02.06" as follows: 1.) "30/02/06" and 2.) "06/02/30" The following code does not works an Idont know whats wrong. String patternForSubstitution = "s/(\\d{2})\\.(\\d{2})\\.(\\d{4})/\\3\\2 1/"; String valueToSubstitute = "30.02.2006"; Pattern p = Pattern.compile(patternForSubstitution); Matcher m = p.matcher(valueToSubstitute); String result = m.replaceAll(valueToSubstitute); I hope anyone can help me, thanks. Jan

99. Regex, String Range    forums.oracle.com

Hello please, Appreciate your help here. I have a field string that wants to find if that exists between two range strings on character basis. Ex: String lower boundary : "ABD" String upper boundary : "ALGKP" field String : "ABE" Now the field string "ABE" exists between "ABD" and "ALGKP". Here the comparison is char-by-char. i.e A is b/w A & ...

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.