当前位置: 动力学知识库 > 问答 > 编程问答 >

regex - Need a Regular expression to extract 5th to 8th charactors in a string

问题描述:

Need a UNIX Regular expression to extract letters from 4th to 8th.

For example: File 15870712.iis

If we want to extract Ist 3 digits we can give

'^([0-9][0-9][0-9])' > 158

I need the 5th 6th 7th and 8th chara. > 0712

网友答案:
$letters = substr($string, 4, 4);

Its not using regular expressions, but does exactly, what you want. According your question there is absolutely no need for complex pattern matching.

网友答案:

Letters or any character? If the latter:

/^....(....)/
网友答案:

This will match digits from position 5 through 8, and assumme any character on the first 4 positions.

^.{4}([0-9]{4})

If you need the first 4 positions to be digits as well you can use this instead:

^[0-9]{4}([0-9]{4})
分享给朋友:
您可能感兴趣的文章:
随机阅读: