Results 1 to 5 of 5

Thread: Regex help....

  1. #1

    Aptmunich's Avatar
    Member Since
    Mar 09, 2004
    Location
    Munich
    Posts
    9,073
    Specs:
    Aluminium Macbook 2.4 Ghz 4GB RAM, SSD 24" Samsung Display, iPhone 4, iPad 2
    Regex help....
    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:

    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?

  2. #2

    xstep's Avatar
    Member Since
    Jun 25, 2005
    Location
    On the road
    Posts
    3,231
    Specs:
    2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
    Lesson: Regular Expressions and Using Regular Expressions in Java may be of value to you.

    I'm not sure, but I think you want;
    Code:
    "((?:[a-zA-Z0-9]+))"
    Why is the question mark in there by it self? This is the only thing I could find about it in one of those links; "Groups beginning with (? are pure, non-capturing groups that do not capture text and do not count towards the group total."
    CameraTime - Time lapse photography for novice and advanced users.

    When asking questions, post the version of your software. You'll receive better answers.

    Please post your results to the thread as it is good feedback.

  3. #3

    Aptmunich's Avatar
    Member Since
    Mar 09, 2004
    Location
    Munich
    Posts
    9,073
    Specs:
    Aluminium Macbook 2.4 Ghz 4GB RAM, SSD 24" Samsung Display, iPhone 4, iPad 2
    Quote Originally Posted by xstep View Post
    Lesson: Regular Expressions and Using Regular Expressions in Java may be of value to you.

    I'm not sure, but I think you want;
    Code:
    "((?:[a-zA-Z0-9]+))"
    Why is the question mark in there by it self? This is the only thing I could find about it in one of those links; "Groups beginning with (? are pure, non-capturing groups that do not capture text and do not count towards the group total."
    Cheers!

    The "?" is there because that's what the regex generator website I used spit back

    txt2re: headache relief for programmers :: regular expression generator

  4. #4

    xstep's Avatar
    Member Since
    Jun 25, 2005
    Location
    On the road
    Posts
    3,231
    Specs:
    2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
    Thanks for the site. I book marked it.
    CameraTime - Time lapse photography for novice and advanced users.

    When asking questions, post the version of your software. You'll receive better answers.

    Please post your results to the thread as it is good feedback.

  5. #5

    Aptmunich's Avatar
    Member Since
    Mar 09, 2004
    Location
    Munich
    Posts
    9,073
    Specs:
    Aluminium Macbook 2.4 Ghz 4GB RAM, SSD 24" Samsung Display, iPhone 4, iPad 2
    Quote Originally Posted by xstep View Post
    Thanks for the site. I book marked it.
    Yeah, it's quite useful - especially if you don't know much about Regex at all like me

    Cheers for the help, it worked a treat!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •