0

What am i missing??

This is the 'dataStoreConstructor' I am passing to the method code below -

url='https://www.salesforce.com/services/Soap/u/26.0',corpnet_prodnet='Corpnet'


  public void registerDataStoreInRepository(String dataStoreConstructor) throws DragonException{
    String constructorPattern = "url='([^']*?)',corpnet_prodnet='([^']*?)'";
    System.out.println(constructorPattern);
    System.out.println(dataStoreConstructor);
    Pattern pattern = Pattern.compile(constructorPattern);
    Matcher matcher = pattern.matcher(dataStoreConstructor);

    SalesforceDataStore sfDataStore = new SalesforceDataStore.Builder(this, matcher.group(1), matcher.group(0)).build();
  };


This is the output I see -

url='([^']*?)',corpnet_prodnet='([^']*?)'Exception in thread "main" 
url='https://www.salesforce.com/services/Soap/u/26.0',corpnet_prodnet='Corpnet'
java.lang.IllegalStateException: No match found
    at java.util.regex.Matcher.group(Matcher.java:485)
    at com.dragon.dictionary.salesforce.SalesforcePlatform.registerDataStoreInRepository(SalesforcePlatform.java:63)
3
  • it works fine here regex101.com/r/lS5tT3/39 Commented Sep 26, 2014 at 5:41
  • sorry for the typo in the output - Why is this causing a 'No match found' exception then? Commented Sep 26, 2014 at 5:45
  • 1
    The pattern looks good, however the lazy quantifiers are useless since you use a negated character class: '([^']*)' Commented Sep 26, 2014 at 5:52

2 Answers 2

3

Regex is fine. Just call :

matcher.find() 

once before calling matcher.group().Your problem will be solved.

Sign up to request clarification or add additional context in comments.

Comments

2

Use this:

if (matcher.find()) {
    SalesforceDataStore sfDataStore = new SalesforceDataStore.Builder(this, matcher.group(1), matcher.group(0)).build();
}

You've forgotten to tell the matcher to go and find something :-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.