简体   繁体   English

Java中用于字母和数字的模式匹配

[英]Pattern matching in Java for alphabets and numbers

I am doing a simple pattern matching, which is not working. 我正在做一个简单的模式匹配,无法正常工作。 Please help 请帮忙

The string is: 字符串是:

The number *TER8347834SC* has problems.

The String contains a number TER8347834SC which may change with different messages, so i need to use regex to match this number while comparing the String. 字符串包含一个数字TER8347834SC ,该数字可能会随不同的消息而变化,因此在比较字符串时,我需要使用正则表达式来匹配该数字。 So while comparing String I am using the regex as [A-Z0-0] for TER8347834SC which doesn't match. 因此,虽然比较字符串我使用正则表达式为[A-Z0-0]TER8347834SC不匹配。

I know this is quite simple, but i tried many times, please help me in this. 我知道这很简单,但是我尝试了很多次,请帮助我。

当消息始终与您提到的相同时,您的模式才应该像这样:

String pattern = "The number (.*) has problems.";

Think you mean this, 以为你是这个意思,

"\\b[A-Z0-9]+\\b"

Note that \\\\b word boundary is a much needed one. 请注意, \\\\b字边界是一个非常需要的边界。

尝试使用这个:

([A-Z]+[0-9]+)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM