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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:31:20+00:00 2026-06-13T18:31:20+00:00

How can i write this as a regular expression? blocka#123#456 i have used #

  • 0

How can i write this as a regular expression?

“blocka#123#456”

i have used # symbol to split the parameters in the data
and the parameters are block name,startX coordinate,start Y corrdinate

this is the data embedded in my QR code.so when i scan the QR i want to check if its the right QR they’re scanning. For that i need a regular expression for the above syntax.

my method body

public void Store_QR(String qr){
   if( qr.matches(regular Expression here)) {
      CurrentLocation = qr;
   }
   else // Break the operation
}
  • 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-13T18:31:22+00:00Added an answer on June 13, 2026 at 6:31 pm

    myregexp.com is nice to do some testing.

    Official Java Regex Tutorial is quite ok to learn and includes most things one needs to know.

    The Pattern documentation also includes fancy predefined character classes that are missing in above tutorial.

    You did not specify anything that has to be regular in that example you gave. Regular expressions make only sense if there are rules to validate the input.

    If it has to be exactly "blocka#123#456" then "blocka#123#456" or "^blocka#123#456$" will work as regex. Stuff between ^ and $ means that the regex inside must span from begin to end of the input. Sometimes required and usually a good idea to put that around your regex.

    If blocka is dynamic replace it with [a-z]+ to match any sequence of lowercase letters a through z with length of at least 1. block[a-z] would match blocka, blockb, etc.
    And [a-z]{6} would match any sequence of exactly 6 letters. [a-zA-Z] also includes uppercase letters and \p{L} matches any letter including unicode stuff (e.g. Blüc本).

    # matches #. Like any character without special regex meaning ( \ ^ $ . | ? * + ( ) [ ] { } ) characters match themselves. [^#] matches every character but #.

    Regarding the numbers: [0-9]+ or \d+ is a generic pattern for several numbers, [0-9]{1,4} would match anything consisting out of 1-4 numbers like 007, 5, 9999. (?:0|[1-9][0-9]{0,3}) for example will only match numbers between 0 and 9999 and does not allow leading zeros. (?:STUFF) is a non-capturing group that does not affect the groups you can extract via Matcher#group(1..?). Useful for logical grouping with |. The meaning of (?:0|[1-9][0-9]{0,3}) is: either a single 0 OR ( 1x 1–9 followed by 0 to 3 x 0–9).

    [0-9] is so common that there is a predefinition for it : \d (digit). It’s \\d inside the regex String since you have to escape the \.

    So some of your options are

    • ".*" which matches absolutely everything
    • "^[^#]+(?:#[^#]+)+$" which matches anything separated by # like "hello #world!1# -12.f #本#foo#bar"
    • "^blocka(#\\d+)+$" which matches blocka followed by at least one group of numbers separated by # e.g. blocka#1#12#0007#949432149#3
    • "^blocka#(?:[0-9]|[1-9][0-9]|[1-3][0-9]{2})#[4-9][0-9]{2}$" which will match only if it finds blocka# followed by numbers 0 – 399, followed by a # and finally numbers 400-999
    • "^blocka#123#456$" which matches only exactly that string.

    All that are regular expressions that match the example you gave.

    But it’s probably as simple as

    public void Store_QR(String qr){
       if( qr.matches("^blocka#\\d+#\\d+$")) {
          CurrentLocation = qr;
       }
       else // Break the operation
    }
    

    or

    private static final Pattern QR_PATTERN = Pattern.compile("^blocka#(\\d+)#(\\d+)$");
    public void Store_QR(String qr){
        Matcher matcher = QR_PATTERN.matcher(qr);
        if(matcher.matches()) {
            int number1 = Integer.valueOf(matcher.group(1));
            int number2 = Integer.valueOf(matcher.group(2));
           CurrentLocation = qr;
        }
        else // Break the operation
     }
    

    BlockName#start_X#start_Y any block name.. starting with the string”block” and followed by two integers

    I guess a good regex for that would be "^block\\w+#\\d+#\\d+$", starting with "block", then any combination of a–z, A–Z, 0–9 and _ (thats the \w) followed by #, numbers, #, numbers.

    Would match block_#0#0, blockZ#9#9, block_a_Unicorn666#0000#1234, but not block#1#2 because there is no name at all and would not match blockName#123#abc because letters instead of number. Would also not match Block_a#123#456 because of the uppercase B.

    If the name part (\\w+) is too liberal (___, _123 would be a legal names) use e.g. "^block_?[a-zA-Z]+#\\d+#\\d+$", what won’t allow numbers and names may only be separated by a single optional _ and there have to be letters after that. Would allow _a, a, _ABc, but not _, _a_b, _a9. If you want to allow numbers in names [a-zA-Z0-9] would be the character class to use.

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

Sidebar

Related Questions

I can't run this regular expression on Java: String regex = /^{m:\(.*)\,s:([0-9]{1,15}),r:([0-9]{1,15}),t:([0-9]{1,2})}$/; String data
How to write Regular Expression which can find this <a href=# onclick=javascript:setSectionName('');showFunctionMenu2( ......>xxxxxx</a> and
I have a regular expression like \r?\n\r?\n . I can write it as (\r?\n){2}
I am wondering if there is a specific regular expression I can write to
I need to write a regular expression for an 'option symbol' for my company
How can I write regular expression in which whenever there is 0000 there should
can some tell how can i write regular expression matching abc.com.ae or abc.net.af or
I'm trying to write a regular expression for this. I need it to grab
I am trying to write a regular expression that can parse the text between
How can I write a regular expression to replace links with no link text

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.