Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2009
    Posts
    173
    Thanks
    24
    Thanked 1 Time in 1 Post

    String matcher help!

    Why this line of code outputs false?

    Code:
    System.out.println("Homer Simpson".matcher("\bSimpson$"));
    I've tried so many different ways like.

    Code:
    System.out.println("Homer Simpson Lol".matcher("\bSimpson\b"));
    System.out.println("Homer Simpson Lol".matcher("\sSimpson\s"));
    System.out.println("Homer Simpson Lol".matcher("Simpson"));
    System.out.println("Homer Simpson Lol".matcher("[ ]Simpson[ ]"));
    Can someone help me to figure out this?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    String doesn't have a matcher method; that should throw a compilation error. Perhaps you mean "matches", but you'll need to give it a full pattern. Perhaps with your lookup you should just use the contains() method.


  •  

    Posting Permissions

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