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 6984925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:36:46+00:00 2026-05-27T18:36:46+00:00

I want to create a pattern for the following format of string. I have

  • 0

I want to create a pattern for the following format of string. I have come with the following format but I am stuck as I am not able to scan it properly. Below are the details

Example String: JAS 5F W 123 or BWER34 23 C 23

Above String has the following rules to be followed.

  1. The last digits can be 2 or 3 digit numbers only (123 && 023 or
    23)
  2. Before that only a single character is allowed case insensitive (W or c)
  3. Before that only 2 digits or one digit and a character only “f”or”F” is allowed.
  4. Starting of string can be any String alphanumeric string of any length.
    All the parts are separated by space
    I came up with the following String pattern but when i run my java program it gives dangling meta character.

    "*\\s([0-9][fF]|[1-9][0-9])\\s([a-zA-Z])\\s(\\d\\d|\\d\\d\\d)$"
    

Please help me in creating the correct pattern for the above String

  • 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-05-27T18:36:46+00:00Added an answer on May 27, 2026 at 6:36 pm

    First of all you use a quantifier but don’t quantify anything: remove the first * or add something before it. This causes the “dangling metacharacter” message.

    Second \\d\\d|\\d\\d\\d could be rewritten to \\d{2,3} (two or three digits).

    Finally, you can make the expression case insensitive by adding a (?i) prefix thus allowing you to write it as follows:

    "(?i).*\\s(\\df|[1-9]\\d)\\s([a-z])\\s(\\d{2,3})$"
    

    Note that I assume you want to match anything before the query and thus I added a dot before the asterisk: .*. If you use Pattern directly (i.e. not String#matches()) you don’t even need that.

    Before that only 2 digits or one digit and a character only “f”or”F” is allowed.

    Would that allow 05 as well (those are two digits)? If so, you could rewrite that part as \\df|\\d{2}

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

Sidebar

Related Questions

Following String causes PatternSyntaxException : Pattern.compile(*\\.*); I want to create a pattern so that
i want create image animation , i have 50 images with png format now
I have the following piece of code pattern: void M1(string s, string v) {
I have the following virtuslhost for my subversion repository and i want to create
I want to create an allocator which provides memory with the following attributes: cannot
I'm looking for a pattern for the following. (I'm working in Perl, but I
I have tried to create a concurrent queue class, in a producer-consumer pattern. I
I'm just wondering if Specification pattern is pointless, given following example: Say you want
I have a string ( $string for this example) and I want to do
As I create tests for a framework, I start noticing the following pattern: class

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.