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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:25:02+00:00 2026-05-26T15:25:02+00:00

I have this data ReferenceDataLocation = as ############################################################################## # # LicenseKey # Address Doctor

  • 0

I have this data

ReferenceDataLocation = as


##############################################################################
#
#   LicenseKey
#       Address Doctor License
#
##############################################################################
LicenseKey = al

which I’d like to capture only key value pairs eg: ReferenceDataLocation = as and LicenseKey = al

I wrote (?xms)(^[\w]+.*?)(?=^[\w]+|\z) regex which is perfect except the fact that it also captures ##### part, which is not key value pair.

Please help me modify the same regex (?xms)(^[\w]+.*?)(?=^[\w]+|\z) to only get ReferenceDataLocation = as and LicenseKey = al

Note: Here you can try out

Update

I tried (?xms)(^[\w]+.*?)(?=^[\w^#]+|\z) it works in the site but gives me an error in java

Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 31
(?xms)(^[\w]+.*?)(?=^[\w^#]+|\Z)
                               ^

Updat Regex that works for me

(?xms)(^[\w]+.*?)(?=^[\w^\s]+|\z)
  • 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-26T15:25:03+00:00Added an answer on May 26, 2026 at 3:25 pm

    You can’t do that with a simple regex-match. You can’t account for occurrences like these:

    # some words here LicenseKey = al
    

    The regex engine cannot look behind from LicenseKey to the end of the line. This is not supported in Java’s regex engine (unbounded look-behinds).

    But what you posted looks like it’s just a properties file. Try this:

    import java.io.FileInputStream;
    import java.util.Properties;
    
    public class Main {
        public static void main(String[] args) throws Exception {
            Properties properties = new Properties();
            properties.load(new FileInputStream("test.properties"));
            System.out.println(properties.getProperty("ReferenceDataLocation"));
            System.out.println(properties.getProperty("LicenseKey"));
            System.out.println(properties.getProperty("foo"));
        }
    }
    

    which will print:

    as
    al
    null

    Note that your input file needn’t be called test.properties, you can give it any name you like.

    And if you don’t know the keys up front, you can simply iterate over all entries in your properties file like this:

    for(Map.Entry<Object, Object> entry : properties.entrySet()) {
      System.out.println(entry.getKey() + " :: " + entry.getValue());
    }
    

    which prints:

    LicenseKey :: al
    ReferenceDataLocation :: as

    And there’s also Properties#stringPropertyNames() which returns a Set<String> that represents all keys in the properties file (see the API docs for more info).

    See:

    • Tutorial: http://download.oracle.com/javase/tutorial/essential/environment/properties.html
    • API docs: http://download.oracle.com/javase/7/docs/api/java/util/Properties.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have this scenario: A server which contains needed data and client component which
I have this data which can be very big in size, this could be
If I have this data in a table in MSSQL which represents a horizontal
I have this data file, which is supposed to be a normal ASCII file.
I have this data structure below, which is a print_r of $_GET: Array (
I have this data and i need an output like this type of output..
I have this data (columns are depth, name, value, the order is correct): 0,
I have this data from a xml file: <?xml version=1.0 encoding=utf-8 ?> <words> <id>...</id>
I have this class: public MyClass { public void initialize(Collection<String> data) { this.data =
Say I have this table schema. ID AccNo Amount Say I have this data

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.