Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8069519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:04:42+00:00 2026-06-05T13:04:42+00:00

I need to check a pattern against some text (I have to check if

  • 0

I need to check a pattern against some text (I have to check if my pattern is inside many texts).

This is my example

String pattern = "^[a-zA-Z ]*toto win(\\W)*[a-zA-Z ]*$";    
if("toto win because of".matches(pattern))
 System.out.println("we have a winner");
else
 System.out.println("we DON'T have a winner");

For my test, the pattern must match but using my regexp does not match.
Must match :

" toto win bla bla"

"toto win because of"
"toto win. bla bla"


"here. toto win. bla bla"
"here? toto win. bla bla"

"here %dfddfd . toto win. bla bla"

Must not match:

" -toto win bla bla"
" pretoto win bla bla"

I try to do it using my regexp but it does not work.

Can you point me what I’m doing wrong ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:04:45+00:00Added an answer on June 5, 2026 at 1:04 pm

    This would work

    (?im)^[?.\s%a-z]*?\btoto win\b.+$
    

    Explanation

    "(?im)" +         // Match the remainder of the regex with the options: case insensitive (i); ^ and $ match at line breaks (m)
    "^" +             // Assert position at the beginning of a line (at beginning of the string or after a line break character)
    "[?.\\s%a-z]" +    // Match a single character present in the list below
                         // One of the characters “?.”
                         // A whitespace character (spaces, tabs, and line breaks)
                         // The character “%”
                         // A character in the range between “a” and “z”
       "*?" +            // Between zero and unlimited times, as few times as possible, expanding as needed (lazy)
    "\\b" +            // Assert position at a word boundary
    "toto\\ win" +     // Match the characters “toto win” literally
    "\\b" +            // Assert position at a word boundary
    "." +             // Match any single character that is not a line break character
       "+" +             // Between one and unlimited times, as many times as possible, giving back as needed (greedy)
    "$"               // Assert position at the end of a line (at the end of the string or before a line break character)
    

    UPDATE 1

    (?im)^[?~`'!@#$%^&*+.\s%a-z]*? toto win\b.*$
    

    UPDATE 2

    (?im)^[^-]*?\btoto win\b.*$
    

    UPDATE 3

    (?im)^.*?(?<!-)toto win\b.*$
    

    Explanation

    "(?im)" +       // Match the remainder of the regex with the options: case insensitive (i); ^ and $ match at line breaks (m)
    "^" +           // Assert position at the beginning of a line (at beginning of the string or after a line break character)
    "." +           // Match any single character that is not a line break character
       "*?" +          // Between zero and unlimited times, as few times as possible, expanding as needed (lazy)
    "(?<!" +        // Assert that it is impossible to match the regex below with the match ending at this position (negative lookbehind)
       "-" +           // Match the character “-” literally
    ")" +
    "toto\\ win" +   // Match the characters “toto win” literally
    "\\b" +          // Assert position at a word boundary
    "." +           // Match any single character that is not a line break character
       "*" +           // Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
    "$"             // Assert position at the end of a line (at the end of the string or before a line break character)
    

    RegEx need to escaped for using within code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I need a string to match this pattern: word1,word2,word3, how would I check
I need to check user input from an EditText against the pattern described before
I need to check in some fast way if there is any text nodes
So I have a String I need to check for a valid format for
I have an entity ArticlePattern , which has a property pattern (string). I need
I need some suggestions in writing a regular expression pattern My string would be
I have some input string with characters and list of string. What I need
I have a string with certain pattern. I need to search for the pattern
I need to be able to check for a pattern with | in them.
I need to check specific positions in an NSArray to see if they have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.