0

currently I wish to extract a Token that is content in string format. I've already seen this topic, but in my context, I don't manage to extract my token. I've got this code:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SOAPParsing {
    public static void main(String[] args) {
        String test = "<BinarySecurityToken Id=\"TotoToken\">Kqdsqd/Jxugtqsk6Ws3q3sd54sq6d4q6sd4qs6d4qs6dq6sd98d69qdq9dsq7d98q7sdqdq7qsddq7Mw2RMmhevkJt/4q6sd7qsIRveuTTqdqsa/zxqsdqdqNg==</BinarySecurityToken>";
        Pattern pattern = Pattern.compile("BinarySecurityToken\\\\Id=\"TotoToken\">\\s:\\s(.+?)\\</BinarySecurityToken>");
        Matcher matcher = pattern.matcher(test);
        if (matcher.find()) {
            System.out.println(matcher.group(1));
        } else {
            System.out.println("nothing ..");
        }
    }
}

How I can fix my problem ?

Thanks in advance,

3
  • Try your regex in some online tool first, i.e. without the Java escaping. As an example: what do you think \\ (non-escaped version) after BinarySecurityToken should match? Commented Mar 31, 2016 at 13:40
  • Thanks for your response, but I get nothing Commented Mar 31, 2016 at 13:48
  • For one thing the part of your Regex, \s:\s is looking to match [whitespace]:[whitespace] which doesn't appear in your string. So even if everything else were correct (which I doubt), it still wouldn't match. Like Thomas said, Google "Regex Tester" and get the pattern to work before you mess with stuffing it in Java. Commented Mar 31, 2016 at 13:57

1 Answer 1

1

Try this as your regex:

"<BinarySecurityToken Id=.*>(.*)</BinarySecurityToken>"

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

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.