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

1. Regular expression to allow a set of characters and disallow others    stackoverflow.com

I want to restrict the users from entering the below special characters in a field:

œç?Ç?
??š??Š???Ž?????ž
??
???
—¿„”*@
Newline
Carriage return
A few more will be added to this list but I will have the complete restricted ...

2. Regular expression for excluding special characters    stackoverflow.com

I am having trouble coming up with a regular expression which would essentially black list certain special characters. I need to use this to validate data in input fields (in a Java ...

3. What is the point behind character class intersections in Java's Regex?    stackoverflow.com

Java's Regex.Pattern supports the following character class:

[a-z&&[def]]
which matches "d, e, or f" and is called an intersection. Functionally this is no different from:
[def]
which is simpler to read and understand in a big ...

4. regex: alternating character / sequential numeric    stackoverflow.com

I am looking for regular expression in java that matches the following pattern:

  1. two alternating numeric or alpha values Example: 12121212 or adadadad
  2. numeric or alpha sequences with at least 4 sequential ...

5. Check String for Alphabetical Characters    stackoverflow.com

If I have the strings "hello8459" and "1234", how would I go about detecting which one had the alphabetical characters in? I've been trying:

//Checking for numerics in an if...
Pattern.matches("0-9", string1);
However it ...

6. Java: RegEx Problem (using the '.' all character symbol)    stackoverflow.com

I have some document stored as a large String. In the String I have some inline XML tags and I want to get out the words inbetween the tags. The documents ...

7. Is regex in Java anchored by default with both a ^ and $ character?    stackoverflow.com

From my understanding of regular expressions string "00###" has to match with "[0-9]", but not to "^[0-9]$". But it doesn't work with Java regexp's. After some investigating of this problem I founded ...

8. Regular Expression avoiding characters up to code 255    stackoverflow.com

Dear Masters! Is it possible to ensure, that only characters with codes between 0 and 255 will be accepted by regular expression, but all with the codes up to 256 not? ...

9. How to check if a character is a non-word boundary    stackoverflow.com

In Java regular expression, it has "\B" as a non-word boundary. http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html If I have a 'char', how can I check it is a non-word boundary? Thank you.

10. Any character including newline - Java Regex    stackoverflow.com

I thought it may be [.\n]+ but that doesn't seem to work?

11. How can i write the regex "All characters are the same"?    stackoverflow.com

I would like it to match:

aaaaaa
bb
c
but not:
aaabaaa
cd
...

12. Java regex predefined character class nested inside character class    stackoverflow.com

I need to use a regular expression that contains all the \b characters except the dot, . Something like [\b&&[^.]] For example, in the following test string: "somewhere deep down in some org.argouml.swingext ...

13. Regex subbing out 'section character' in java    stackoverflow.com

I'm running a series of regex substitutions (i.e. String.replaceAll calls) to convert all the special characters in a text file to XML parseable special characters. For example:

string_out = string_out.replaceAll("&", "&");
I've hit ...

14. Java RegEx meta character (.) and ordinary dot?    stackoverflow.com

In Java RegEx, how to find out the difference between .(dot) the meta character and the normal dot as we using in any sentence. How to handle this kind of situation ...

15. make characters optional in regular expression    stackoverflow.com

I am trying to validate a (US) phone number with no extra characters in it. so the format is 1-555-555-5555 with no dashes, spaces, etc and the 1 is optional. ...

16. What is a regular expression for control characters?    stackoverflow.com

I'm trying to match a control character in the form \^c where c is any valid character for control characters. I have this regular expression, but it's not currently working: \\[^][@-z] I ...

17. Prepend set of characters    stackoverflow.com

I need to prepend a backlash to all occurrences of characters from a set, say '"\, in a given string. For example, given the string

He said "I don't know."
it should be replaced ...

18. Accepting only a single character in a row in a regular expression    stackoverflow.com

I'm trying to split a string formatted like Bananas|,|Bananas|||Bananas|Oranges|,|Bananas|||Bananas|Oranges|||Bananas|Oranges|Green Apples|,|Bananas|||Bananas|Oranges|||Bananas|Oranges|Red Apples|,|Bananas|||Bananas|Oranges|||Bananas|Oranges|Pears with a regex, on the ||| or |,| delimiters. I'm using [a-zA-Z |]+\|[,|\0]\|, but I have a small issue: the ...

19. Regex to ignore leading characters    stackoverflow.com

I'm sure there's a simple solution to this but it's got me stuck so hopefully someone can give me a hand. I've got multiple lines of input that look like this:

FooABC
Foo ...

20. How to create a character class of the following set    stackoverflow.com

+ - * / % < > = ! & ^ | ? :
I've tried:
[+-*/%<>=!&^|?:]
But I think some of them will need to be scaped. How can I tell which ...

21. checking if a string has special characters    stackoverflow.com

how would i check a string for special characters such as $%#, and numbers? I only want chars, ex abcd. the only method i can think of is to make an arraylist of ...

22. Regex Question - Exclude Certain Characters    stackoverflow.com

If I want to exclude /* in regex how would I write it? I have tried:

[^/[*]]
([^/][^*])
But to no avail...

23. How to create a regex for accepting only alphanumeric characters?    stackoverflow.com

Possible Duplicate:
Regular Expression for alphanumeric and underscores
How to create a regex for accepting only alphanumeric characters? Thanks.

24. How do you write a regular expression that allows the special character DOT?    stackoverflow.com

How do you write a regular expression that allows the character DOT(.) in a user name? For example:

R. Robert
X. A. Pauline 

25. Is there a way to use \p{Punct} in a regex(java), but without the "(",")" characters?    stackoverflow.com

Is there a way to use the patter \p{Punct} in a regex in java, but without the two characters ( and ) ?

26. How to know Which character was replaced while using regex    stackoverflow.com

String string = "T?ï? ?š â f???? Š?????s not cool \"oops" ;    
    string = string.replaceAll("[^a-zA-Z0-9 ]+", ... );
The problem is that I want to ...

27. POSIX character equivalents in Java regular expressions    stackoverflow.com

I would like to use a regular expression like this in Java : [[=a=][=e=][=i=]].
But Java doesn't support the POSIX classes [=a=], [=e=] etc. How can I do this? More precisely, is there ...

28. Can I define custom character class shorthands?    stackoverflow.com

Java provides some useful character classes like \d and \w. Can I define my own character classes? For example, it would be useful to be able to define shorthands for character ...

29. regex repeated character count    stackoverflow.com

If I have a set of characters like "abcdefghij" and using this characters, I generate random a password using this characters. A generated password can have, for example, 6 characters. How ...

30. Error in regex when first character is \ works fine with any other character    stackoverflow.com

For a project that I am doing I have to read a String. This String may contain one or more hexadecimal representations of unicode characters (e.g. "\u0161" for "š"). I want ...

31. Check Non-Numeric characters in String    stackoverflow.com

I want to check whether the String contains only numeric characters or it contains alpha-numeric characters too. I have to implement this check in database transaction where about a hundred-thousand records are ...

32. Java - How to check for duplicate characters in a string?    stackoverflow.com

I need to write a function that checks a string for duplicate values and returns the count of unique characters. If the count is greater than 3, it should return true. ...

33. Regular expression to check allowed characters not working in Java    stackoverflow.com

I have the following method to check allowed characters:

private boolean checkIfAllCharsAreValid(String test) {
    boolean valid = false;
    if (test.matches("^[a-zA-Z0-9,.;:-_'\\s]+$")) {
      ...

34. Best way to get all character indexes for a given phrase located in text    stackoverflow.com

What is the best way to get all character positions of a search phrase for a given string of text? For example, say we have "the red cat is watching the red ...

35. Java RegEx - Illegal character dot    stackoverflow.com

String filter = "a-zA-Z0-9äöüÄÖÜß-\\.";
"^[^" + filter + "]*$", ""

inputtext.replaceAll("^[^" + filter + "]*$", "");
This Java RegEx filter should remove all characters from inputtext except the characters in filter, but I'm getting ...

36. How to check special characters in java code using Java.util.regex package    coderanch.com

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ...

39. Regex help, replacing/espacing characters    coderanch.com

Hey all, I needed a little help writing a function in java that does the follow for escaping, I want to use regular expressions, I need the following characters to be replaced by a ~ I posted it in beginners, but i think it is more fitting in this area. The special characters are replaced as follows: 1. Newline, backspace, Control-M, ...

42. Regex for allowing alpha characters and wildcard %    coderanch.com

I'm trying to understand what you are looking for. Are you wanting to fish a substring out? Are you wanting to know the boolean: match or not match? Can you give some examples of strings that are a match and strings that are a fail? For me, I find that anytime I do regex, I first write a ton of unit ...

43. regex utf-8 characters    coderanch.com

hi. would like some inputs String diamond = String.valueOf(new Character('\u2666')); what my program does is to replace space characters with diamond symbols and pass them to the JTextPane for display. it works. my problem is when i revert it back from diamonds to space characters. i used regex via the String's replaceAll() method but it does not work. naturally, if i ...

44. RegExp and UTF-8 Characters    java-forums.org

45. regular expression for character ^    forums.oracle.com

47. Regex character classes    forums.oracle.com

48. Regular Expressions to Omit Characters    forums.oracle.com

49. Regex help to locate the character /    forums.oracle.com

53. Regex help needed, please for < , > and = characters    forums.oracle.com

As is understood, I am new to regex. I want to search for the characters '<'>' and '=' followed by any character except a space, and replace it with the same with a space inserted after that character. I do not want to read through the same string thrice for each character that '<'>' and '=' followed by any character except ...

54. how to check if there is any other character than "0" - regex?    forums.oracle.com

Hi Guys Simple if i have few strings eg "00000000000" or "000F0000000" or "a0000000" how do I find using regex, that whether the strings has any other value than 0 OR they all all 0s. i tried Pattern.compile("[^0]"); on above strings, Then I use pattern.matcher for above strings I expect false, true, true for above strings respectively? but it returns false ...

55. A problem with regex and special characters    forums.oracle.com

because split will not work when trying to replace the first word if i don't append a space at the beginning. replaceAll will replace all the occurrences in the text with only one word. without taking into consideration the case of the word i need to replace. If i use replacaAll(article, strToFind) the output will be: go? G?oing go? to gOschool ...

57. Regex for international character sets like [a-zA-Z] + , ?, , etc.    forums.oracle.com

Hi all! Is there an internationalized equivalent for the pattern "[a-zA-Z]+" which would accept the French, German, Polish or other local characters like "" or "" or ""? It's a bad idea to add all of them to the standard regex like "[a-zA-Z]+", since you never know what comes next. I tried to use the " p{Alpha}+" to check the string ...

59. regex question - character class and regex    forums.oracle.com

Hello world! I want to use regex in Java but without success. Any clues for this situation ? I am trying to write a method that generate password. However, I want to exclude come character that might easily confused. If I found the string matches these character(s), I will regen. I try to write this in Java, but doesn't match. Pattern.matches ...

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.