mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 17:37:40 +08:00
支持正则匹配规则
This commit is contained in:
parent
2801b0983a
commit
01072e9086
@ -53,7 +53,7 @@ Android手机监听短信并根据指定规则转发到其他手机:钉钉机
|
|||||||
- [x] 支持双卡手机,增加卡槽标识/运营商/手机号(如果能获取的话)
|
- [x] 支持双卡手机,增加卡槽标识/运营商/手机号(如果能获取的话)
|
||||||
- [x] 支持多重匹配规则
|
- [x] 支持多重匹配规则
|
||||||
- [x] 支持标注卡槽号码(优先使用)、设备信息;自定义转发信息模版
|
- [x] 支持标注卡槽号码(优先使用)、设备信息;自定义转发信息模版
|
||||||
- [ ] 支持正则匹配规则
|
- [x] 支持正则匹配规则
|
||||||
- [x] 支持卡槽匹配规则
|
- [x] 支持卡槽匹配规则
|
||||||
- [ ] 转发规则、发送方配置导出与导入
|
- [ ] 转发规则、发送方配置导出与导入
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@ import com.idormy.sms.forwarder.utils.RuleLineUtils;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.regex.PatternSyntaxException;
|
||||||
|
|
||||||
public class RuleModel {
|
public class RuleModel {
|
||||||
public static final String FILED_TRANSPOND_ALL = "transpond_all";
|
public static final String FILED_TRANSPOND_ALL = "transpond_all";
|
||||||
@ -20,6 +22,7 @@ public class RuleModel {
|
|||||||
public static final String CHECK_START_WITH = "startwith";
|
public static final String CHECK_START_WITH = "startwith";
|
||||||
public static final String CHECK_END_WITH = "endwith";
|
public static final String CHECK_END_WITH = "endwith";
|
||||||
public static final String CHECK_NOT_IS = "notis";
|
public static final String CHECK_NOT_IS = "notis";
|
||||||
|
public static final String CHECK_REGEX = "regex";
|
||||||
public static final Map<String, String> CHECK_MAP = new HashMap<String, String>();
|
public static final Map<String, String> CHECK_MAP = new HashMap<String, String>();
|
||||||
public static final String CHECK_SIM_SLOT_ALL = "ALL";
|
public static final String CHECK_SIM_SLOT_ALL = "ALL";
|
||||||
public static final String CHECK_SIM_SLOT_1 = "SIM1";
|
public static final String CHECK_SIM_SLOT_1 = "SIM1";
|
||||||
@ -87,6 +90,8 @@ public class RuleModel {
|
|||||||
return CHECK_START_WITH;
|
return CHECK_START_WITH;
|
||||||
case R.id.btnEndWith:
|
case R.id.btnEndWith:
|
||||||
return CHECK_END_WITH;
|
return CHECK_END_WITH;
|
||||||
|
case R.id.btnRegex:
|
||||||
|
return CHECK_REGEX;
|
||||||
case R.id.btnNotIs:
|
case R.id.btnNotIs:
|
||||||
return CHECK_NOT_IS;
|
return CHECK_NOT_IS;
|
||||||
default:
|
default:
|
||||||
@ -161,6 +166,20 @@ public class RuleModel {
|
|||||||
checked = msgValue.endsWith(this.value);
|
checked = msgValue.endsWith(this.value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CHECK_REGEX:
|
||||||
|
if (msgValue != null) {
|
||||||
|
try {
|
||||||
|
checked = Pattern.matches(this.value, msgValue);
|
||||||
|
} catch (PatternSyntaxException e) {
|
||||||
|
checked = false;
|
||||||
|
Log.d(TAG, "PatternSyntaxException: ");
|
||||||
|
Log.d(TAG, "Description: " + e.getDescription());
|
||||||
|
Log.d(TAG, "Index: " + e.getIndex());
|
||||||
|
Log.d(TAG, "Message: " + e.getMessage());
|
||||||
|
Log.d(TAG, "Pattern: " + e.getPattern());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -207,6 +226,8 @@ public class RuleModel {
|
|||||||
return R.id.btnStartWith;
|
return R.id.btnStartWith;
|
||||||
case CHECK_END_WITH:
|
case CHECK_END_WITH:
|
||||||
return R.id.btnEndWith;
|
return R.id.btnEndWith;
|
||||||
|
case CHECK_REGEX:
|
||||||
|
return R.id.btnRegex;
|
||||||
case CHECK_NOT_IS:
|
case CHECK_NOT_IS:
|
||||||
return R.id.btnNotIs;
|
return R.id.btnNotIs;
|
||||||
default:
|
default:
|
||||||
|
@ -7,6 +7,8 @@ import com.idormy.sms.forwarder.model.vo.SmsVo;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.regex.PatternSyntaxException;
|
||||||
|
|
||||||
class RuleLine {
|
class RuleLine {
|
||||||
public static final String CONJUNCTION_AND = "并且";
|
public static final String CONJUNCTION_AND = "并且";
|
||||||
@ -19,6 +21,7 @@ class RuleLine {
|
|||||||
public static final String CHECK_CONTAIN = "包含";
|
public static final String CHECK_CONTAIN = "包含";
|
||||||
public static final String CHECK_START_WITH = "开头";
|
public static final String CHECK_START_WITH = "开头";
|
||||||
public static final String CHECK_END_WITH = "结尾";
|
public static final String CHECK_END_WITH = "结尾";
|
||||||
|
public static final String CHECK_REGEX = "正则";
|
||||||
public static List<String> CONJUNCTION_LIST = new ArrayList<String>();
|
public static List<String> CONJUNCTION_LIST = new ArrayList<String>();
|
||||||
public static List<String> FILED_LIST = new ArrayList<String>();
|
public static List<String> FILED_LIST = new ArrayList<String>();
|
||||||
public static List<String> SURE_LIST = new ArrayList<String>();
|
public static List<String> SURE_LIST = new ArrayList<String>();
|
||||||
@ -315,6 +318,20 @@ class RuleLine {
|
|||||||
checked = msgValue.endsWith(this.value);
|
checked = msgValue.endsWith(this.value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CHECK_REGEX:
|
||||||
|
if (msgValue != null) {
|
||||||
|
try {
|
||||||
|
checked = Pattern.matches(this.value, msgValue);
|
||||||
|
} catch (PatternSyntaxException e) {
|
||||||
|
checked = false;
|
||||||
|
logg("PatternSyntaxException: ");
|
||||||
|
logg("Description: " + e.getDescription());
|
||||||
|
logg("Index: " + e.getIndex());
|
||||||
|
logg("Message: " + e.getMessage());
|
||||||
|
logg("Pattern: " + e.getPattern());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,13 @@
|
|||||||
android:text="结尾"
|
android:text="结尾"
|
||||||
android:textSize="13sp" />
|
android:textSize="13sp" />
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/btnRegex"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="正则"
|
||||||
|
android:textSize="13sp" />
|
||||||
|
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user