- Joined
- Mar 9, 2004
- Messages
- 9,065
- Reaction score
- 331
- Points
- 83
- Location
- Munich
- Your Mac's Specs
- Aluminium Macbook 2.4 Ghz 4GB RAM, SSD 24" Samsung Display, iPhone 4, iPad 2
Hey guys!
I'm working on a uni project and am having trouble parsing a string using regex. (this is a Java project)
Example:
"@John23 This is my message".
I want to be able to recognize "@John23", so I can route the message only to the user "John23".
I can get it working without numerals using this code as the regex input strings:
But I've been having trouble getting it working with any type of ASCII character as the username. I think it's as simple as extending the "re2" String to include 0-9 etc.
Or making "re2" accept any characters, except whitespace (I think ".*" would also include whitespace, correct?).
Any ideas?
I'm working on a uni project and am having trouble parsing a string using regex. (this is a Java project)
Example:
"@John23 This is my message".
I want to be able to recognize "@John23", so I can route the message only to the user "John23".
I can get it working without numerals using this code as the regex input strings:
Code:
String re1="(@)"; // PM Identifier
String re2="((?:[a-z][a-z]+))"; // Username
String re3="(\\s+)"; // White Space = separator username / message
But I've been having trouble getting it working with any type of ASCII character as the username. I think it's as simple as extending the "re2" String to include 0-9 etc.
Or making "re2" accept any characters, except whitespace (I think ".*" would also include whitespace, correct?).
Any ideas?