Finding substring in RegEx Java

后端 未结 5 520
北海茫月
北海茫月 2021-01-24 02:45

Hello I have a question about RegEx. I am currently trying to find a way to grab a substring of any letter followed by any two numbers such as: d09.

I came up with the R

5条回答
  •  孤街浪徒
    2021-01-24 03:09

    1. Your regex is anchored, as such it will never match unless the whole input matches your regex. Use [a-z][0-9]{2}.

    2. Don't use .matches() but .find(): .matches() is shamefully misnamed and tries to match the whole input.

提交回复
热议问题