diff --git a/build.gradle b/build.gradle
index 0946bf4..3a6772a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ plugins {
}
group 'dmitriy.molchanov'
-version '1.4'
+version '1.4.1'
repositories {
mavenCentral()
@@ -27,6 +27,10 @@ intellij {
}
patchPluginXml {
changeNotes """
+ 1.4.1
+
1.4
- Added the ability to add additional text around the result regex value.
diff --git a/src/main/kotlin/dmitriy/molchanov/ui/add/AddRuleDialog.kt b/src/main/kotlin/dmitriy/molchanov/ui/add/AddRuleDialog.kt
index 144f405..50114eb 100644
--- a/src/main/kotlin/dmitriy/molchanov/ui/add/AddRuleDialog.kt
+++ b/src/main/kotlin/dmitriy/molchanov/ui/add/AddRuleDialog.kt
@@ -162,9 +162,9 @@ class AddRuleDialog(
shouldOkButtonActive = false
) to null
}
- val regex = Regex(prefixEdit.text)
+ val regex = prefixEdit.text.getRegexOrNull()
val checkStr = checkStringEdit.text
- regex.find(checkStr)?.range?.apply {
+ regex?.find(checkStr)?.range?.apply {
val lastMatch = if (last == checkStr.length) last else last + 1
val startText = checkStr.substring(0, first)
val matchText = checkStr.substring(first, lastMatch)
@@ -187,7 +187,7 @@ class AddRuleDialog(
private fun String.formatByParams(): String {
val prefix = startWithEdit.text
val suffix = endWithEdit.text
- val registeredValue = when(shouldRuleBuUpperCase()){
+ val registeredValue = when (shouldRuleBuUpperCase()) {
true -> uppercase()
false -> lowercase()
else -> this
@@ -213,6 +213,13 @@ class AddRuleDialog(
else -> Strings.REGISTER_NONE
}
+ private fun String.getRegexOrNull(): Regex? =
+ try {
+ Regex(this)
+ } catch (throwable: Throwable) {
+ null
+ }
+
private class DialogStatus(val message: String, val shouldOkButtonActive: Boolean)
private companion object {