import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\*\\h*\\[(?:x| )\\])\\h*(\\w*)";
final String string = "* [x] homepage_url\n"
+ "* [x] description_good\n"
+ "* [x] interact\n"
+ "* [x] contribution\n"
+ "* [x] contribution_requirements\n"
+ "* [x] floss_license\n"
+ "* [x] floss_license_osi\n"
+ "* [x] license_location\n"
+ "* [x] documentation_basics\n"
+ "* [x] documentation_interface\n"
+ "* [x] sites_https\n"
+ "* [x] discussion\n"
+ "* [x] english\n"
+ "* [x] repo_public\n"
+ "* [x] repo_track\n"
+ "* [x] repo_interim\n"
+ "* [x] repo_distributed\n"
+ "* [x] version_unique\n"
+ "* [x] version_semver\n"
+ "* [x] version_tags\n"
+ "* [x] release_notes\n"
+ "* [ ] release_notes_vulns (@marmarek: Are QSBs always mentioned in release notes?)\n"
+ "* [x] report_process\n"
+ "* [x] report_tracker\n"
+ "* [x] report_responses\n"
+ "* [x] enhancement_responses\n"
+ "* [x] report_archive\n"
+ "* [x] vulnerability_report_process\n"
+ "* [x] vulnerability_report_private\n"
+ "* [x] build\n"
+ "* [ ] build_common_tools (@marmarek: Does `qubes-builder` use \"common tools\"?)\n"
+ "* [x] build_floss_tools\n"
+ "* [x] test\n"
+ "* [ ] test_invocation (@marmarek: Please fill in all \"test\" and \"warning\" criteria met.)\n"
+ "* [ ] test_most\n"
+ "* [ ] test_continuous_integration\n"
+ "* [ ] test_policy\n"
+ "* [ ] tests_are_added\n"
+ "* [ ] tests_documented_added\n"
+ "* [ ] warnings\n"
+ "* [ ] warnings_fixed\n"
+ "* [ ] warnings_strict\n"
+ "* [x] know_secure_design\n"
+ "* [x] know_common_errors\n"
+ "* [x] crypto_published\n"
+ "* [x] crypto_call\n"
+ "* [x] crypto_floss\n"
+ "* [x] crypto_keylength\n"
+ "* [x] crypto_working\n"
+ "* [x] crypto_weaknesses (arguably `qvm-backup` still passes despite #971)\n"
+ "* [x] crypto_pfs\n"
+ "* [x] crypto_password_storage\n"
+ "* [x] crypto_random\n"
+ "* [x] delivery_mitm\n"
+ "* [x] delivery_unsigned\n"
+ "* [x] vulnerabilities_fixed_60_days\n"
+ "* [x] vulnerabilities_critical_fixed\n"
+ "* [x] no_leaked_credentials\n"
+ "* [ ] static_analysis (@marmarek: Please fill in all \"analysis\" criteria met.)\n"
+ "* [ ] static_analysis_common_vulnerabilities\n"
+ "* [ ] static_analysis_fixed\n"
+ "* [ ] static_analysis_often\n"
+ "* [ ] dynamic_analysis\n"
+ "* [ ] dynamic_analysis_enable_assertions\n"
+ "* [ ] dynamic_analysis_fixed\n\n"
+ "Future Criteria\n"
+ "-------------\n\n"
+ "* [x] installation_common (depends on how this applies to OSes)\n"
+ "* [ ] build_reproducible\n"
+ "* [x] crypto_used_network\n"
+ "* [x] crypto_tls12\n"
+ "* [x] crypto_certificate_verification\n"
+ "* [x] crypto_verification_private\n"
+ "* [ ] hardened_site\n"
+ "* [ ] hardening\n";
final String subst = "\\1 [\\2](https://github.com/linuxfoundation/cii-best-practices-badge/blob/master/doc/criteria.md#\\2)";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html