开发者

Need a Regular expression to extract 5th to 8th characters in a string

开发者 https://www.devze.com 2023-03-19 20:09 出处:网络
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

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})
0

精彩评论

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