开发者

Writing regular expression

I need the regex for following type of string: F_E/S_(characters/digits or combination of those)_(characters/digits or combination of those)

Here / means either E or S. How can it be written? I want to match one string in this form.How can it b开发者_高级运维e done in java? I am newbie to Java.


Do the brackets belong to the expression? Can you give an example, please.

Maybe the following regex works already:

"F_[ES]_[A-Za-z0-9]+_[A-Za-z0-9]+"

Use it in this way:

Pattern pattern = Pattern.compile("F_[ES]_[A-Za-z0-9]+_[A-Za-z0-9]+");
Matcher matcher = pattern.matcher(myStringToMatch);
if (matcher.matches())
{
  // Yeah, Baby!
}

If there is no possibility for lower case characters, you can skip the occurrences of a-z in the regex pattern.


Here it´s the regex

F\_[ES]{1}\_([\w\d]+)\_([\w\d]+)


the regex will be F_[ES]_[A-Za-z0-9]+_[A-Za-z0-9]+

Take a look at the Java package java.util.regex and try to write a pattern matching method - its really simple. Post another question citing your java code if you get stuck somewhere..


Another way to write it:

F_[ES]_[^\W_]+_[^\W_]+

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜