Finding substring in RegEx Java

后端 未结 5 518
北海茫月
北海茫月 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:06

    ^[a-z]{1}[0-9]{2}$

    sedfdhajkldsfakdsakvsdfasdfr30.reed.op.1xp0

    as far as i can read this

    • find thr first lower gives[s] caps letter after it there should be two numbers meaning the length of your string is and always will be 3 word chars

    Maybe if i have more data about your string i can help

    EDIT

    if you are sure of *number of dots then

    change this line

    Matcher matcher = pattern.matcher("sedfdhajkldsfakdsakvsdfasdfr30.reed.op.1xp0");
    

    to

    Matcher matcher = pattern.matcher("sedfdhajkldsfakdsakvsdfasdfr30.reed.op.1xp0".split("\.")[0]);
    

    note:-

    using my solution you should omit the leading ^ for pattern

    read this page for Spliting strings

提交回复
热议问题