character « Match « 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 » Match » character 

1. In a java regex, how can I get a character class e.g. [a-z] to match a - minus sign?    stackoverflow.com

Pattern pattern = Pattern.compile("^[a-z]+$");
String string = "abc-def";
assertTrue( pattern.matcher(string).matches() ); // obviously fails
Is it possible to have the character class match a "-" ?

2. How do I use regex to split a string into characters?    stackoverflow.com

I need to learn RegEx but don't have time to figure this out right now. -- So I'm attempting exploit the community's capabilities. I have a string containing a list of acceptable ...

3. excluding matching characters in regular expression    stackoverflow.com

I'm stuck with a regular expression problem. I've got a string which I need to match. The string always starts with 2 letters, and then is followed by a 6 digit number, ...

4. Java Regular Expression value.split("\\."), The Forward Slash Dot divides by character?    stackoverflow.com

From what I understand, the backslash dot ("\.") means one character of any character right? So because backslash is an escape it should be backslash backslash dot ("\\.") What does this do ...

5. To split only Chinese characters in java    stackoverflow.com

I am writing a java application; but stuck on this point. Basically I have a string of Chinese characters with ALSO some possible Latin chars or numbers, lets say:

??????????????210?????.
I want to split ...

6. Splitting a string at every n-th character    stackoverflow.com

In JavaScript this is how we can split a string at every 3-rd character

"foobarspam".match(/.{1,3}/g)
I am trying to figure out how to do this in Java. Any pointers?

7. regex for matching strings that have illegal filename characters    stackoverflow.com

I been trying to figure out how this blasted regex for two hours!!! It's midnight I gotta figure this out and go to bed!!!

String str = new String("filename\\");
if(str.matches(".*[?/<>|*:\"{\\}].*")) {
  ...

8. Java split is eating my characters    stackoverflow.com

I have a string like this String str = "la$le\\$li$lo". I want to split it to get the following output "la","le\\$li","lo". The \$ is a $ escaped so it should be left ...

9. How to match "any character" in Java Regular Expression?    stackoverflow.com

The following should be matched:

AAA123
ABCDEFGH123
XXXX123
can i do: ".*123"?

10. Why regular expression in Java cannot recognize \s as space character?    stackoverflow.com

I read from a lot of webpage (for example: http://www.wellho.net/regex/java.html), they all mentioned that \s could represent any space charactor. But when I use \s in Java, it is ...

11. Regular Expression to match more than one occurrence of a character    stackoverflow.com

I need help coming up with a regular expression to match if a string has more than one occurrence of character. I already validated the length of the two strings and ...

12. Reg Ex Add a space character between alpha and numeric in a string    stackoverflow.com

Hi I have this kind of strings and I want to obtain Like toto100 to become toto 100 Thanks for your help

13. Regex to match a single character    stackoverflow.com

I was wondering if there was a regex availabe that can match a string and search for a "=" in the string.

14. match a string of characters between tags:    stackoverflow.com

I have the following strings:

&#60;PAUL SAINT-KARL 1997-05-07&#62;
&#60;BOB DEAN 2001-05-07&#62;
&#60;GUY JEDDY 2007-05-07&#62;
I want a java regex that would match this type of pattern "name and date" and then extract the name and ...

15. Java - Unknown characters passing as [a-zA-z0-9]*?    stackoverflow.com

I'm no expert in regex but I need to parse some input I have no control over, and make sure I filter away any strings that don't have A-z and/or 0-9. When ...

16. Java Regexp to Match ASCII Characters    stackoverflow.com

What regex would match any ASCII character in java? I've already tried:

^[\\p{ASCII}]*$
but found that it didn't match lots of things that I wanted (like spaces, parentheses, etc...). I'm hoping to avoid explicitly ...

17. Match a Thai Script character in Java    stackoverflow.com

Over last two hours I have a lot of sexy time with Thai Script strings that slipped in my database. They collate mysteriously, mutate when output, do not have natural order ...

18. Regex allowing a space character in Java    stackoverflow.com

Hey all, so I'm trying to allow some text input which goes through a regex check before it's sent off. I want the text to only include A-Z, 0-9, and the ...

19. Regular expression to match French and German characters     stackoverflow.com

I am parsing the request parameters to find any vulnerable characters to prevent XSS threats. Our web application supports both French and German languages other than English. I am using the ...

20. Apply regex conditions after certain character    stackoverflow.com

I have a string that i want to parse into an array. The given string has the form P[AB, AC, AD] (A1, A2, A3). I want to store it in an array like ...

21. Regular expression to match unescaped special characters only    stackoverflow.com

I'm trying to come up with a regular expression that can match only characters not preceded by a special escape sequence in a string. For instance, in the string Is ? stranded//? ...

22. Match only first and last character of a string    stackoverflow.com

I had a look at other stackoverflow questions and couldn't find one that asked the same question, so here it is: How do you match the first and last characters of a ...

23. Java regular expression to match {{characters inside double curly brace}}    stackoverflow.com

I am trying to match everything inside double curly brackets in a string. I am using the following expression:

\{\{.*\}\}
Some examples:
The {{dog}} is not a cat. This correctly matches {{dog}}
However,
The {{dog}} is ...

24. How do you do pattern matching with Chinese characters (encoded in UTF-8) in Java?    stackoverflow.com

I need to check whether a Chinese province is contained within an address in Chinese. I am able to read and write Chinese characters easily. I tried to use the indexOf() method of ...

25. Match nested characters into their meanings with Regex    stackoverflow.com

First of all I'm a toddler when it comes to regular expressions. I need to match nested characters with their meanings stored in an array. It's like a symbol-to-text translator. For example, given this ...

26. Using regex to match non-word characters BUT NOT smiley faces    stackoverflow.com

I have a Java program which is supposed to remove all non-letter characters from a string, except when they are a smiley face such as =) or =] or :P It's very ...

27. Java string.split - by multiple character delimiter    stackoverflow.com

I would like to parse entire file based on all the possible delimiters like commas, colon, semi colons, periods, spaces, hiphens etcs. Suppose I have a hypothetical string line "Hi,X How-how are:any ...

28. How to make regex matching fail if checked string still has leftover characters?    stackoverflow.com

I'm trying to check a string with a regular expression, and this check should only pass if the string contains only *h, *d, *w and/or *m where * can be any ...

29. Confusion over Regex greedy operator, and terminating character    stackoverflow.com

I'm studying up for the SCJP exam, and the following mock question caught me offguard. The explanation in the tool wasn't very good so I'm hoping the knowledgeable people of SO ...

31. RegEx question: How to match the character {    coderanch.com

Hi all, I am trying to write a RegEx Pattern to replace the MessageFormat variables in a properties string (e.g. "My name is {0}" should be changed to "My name is {0}". What seemed like a straighforward task, is getting more complicated, because there seems to be no way to match the { character. I have tried the following, but ...

32. regex : match any character ?    coderanch.com

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.