PHP preg_match_all regex confusion
this is the data
Stream #0.0(ger): Audio: aac, 48000 Hz, stereo, s16 (default)
Stream #0.1: Audio: wmav2 (a[1][0][0] / 0x0161), 48000 Hz, 2 channels, s16, 160 kb/s
this is the pattern
开发者_JAVA百科/Stream #([0-9\.]+).([A-Za-z0-9]+).+Audio/
I need the full numbers string e.g 0.0 or 0.1 plus the audio language (ger) if it has one !
My pattern does not work Can anyone help out ?
"/Stream #([0-9\.]+).([A-Za-z0-9]+).+Audio/"
The parens in ([A-Za-z0-9]+)
are being interpreted as groups, not actual characters. You need to escape them with backslashes.
"/Stream #([0-9\.]+).\\([A-Za-z0-9]+\\).+Audio/"
But if you want this part to be optional, you need to put another set of parens around it, and attach ?
to make it optional:
"/Stream #([0-9\.]+).(\\([A-Za-z0-9]+\\))?.+Audio/"
Try this:
/Stream #(\d+\.\d+)(\([A-Za-z0-9]+\))?.+Audio/
It should return number i.ex.: 0.0 as \1 group and (ger) as \2 group if exists.
精彩评论