Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
built in regex in java strings
12-07-2009, 05:16 PM (This post was last modified: 12-07-2009 05:17 PM by codecaine.)
Post: #1
built in regex in java strings
This is a example of how java string methods have built in regex

Code:
String name = "jerome443scott449II";
name = name.replaceAll("[0-9]+", " "); //[0-9] means any number the + sign after it means keep going until not a number encounter then replace those numbers with a space
System.out.println(name);
Visit this user's website Find all posts by this user
Quote this message in a reply
12-07-2009, 07:07 PM (This post was last modified: 12-07-2009 07:08 PM by Alphablend.)
Post: #2
RE: built in regex in java strings
nice one. thanks. there are many interesting functions with string.
Class String

[Image: 45669_pythonlogo.png][Image: 45668_javalogo.png]
Find all posts by this user
Quote this message in a reply
01-18-2010, 08:54 PM (This post was last modified: 01-18-2010 08:54 PM by RecursiveQuickSort.)
Post: #3
RE: built in regex in java strings
I'd like to practice lots of regular expressions in BeanShell, so I may shorten this to one line like this.

System.out.println("jerome443scott449II".replaceAll("[0-9]+", " "));
Find all posts by this user
Quote this message in a reply
01-19-2010, 04:06 AM
Post: #4
RE: built in regex in java strings
Very good function. Other programming languages have replace function too. If they don't you can make it !

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
01-19-2010, 05:53 AM
Post: #5
RE: built in regex in java strings
Yea but not many have built in regex in theirs Smile
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: