I need a pure regex (no language) to separate the numbers of this input array:
L1,3,5,0,5,80,40,31,0,0,0,0,512,412,213,900
Issues:
L1
) is fixed. The array will always start with L1
. I tried this regex [^;,]*
but it wasn't able to get each data separately.
Can anyone help me on this issue?
With 'pure regex' to get each field, you have to use separate capture groups:
^L(\d),(\d+),(\d+),(\d+),(\d+),(\d+),(\d+),(\d+),(\d+),(\d+),(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)$
(Note: In Python, Perl, Ruby, Java, etc you can have a global find and capture like /(\d+)/g
but that is the language gathering up the matches into a list...)
If you want just one specific field, you can use numbered repetition.
^L(\d)(,(\d+)){N}
Capture group 3 would always be field N-1
so to capture 213, the 15th field, in your example:
^L(\d)(,(\d+)){14}
Trying to refine dawg's approach such that less capturing groups are used:
The fourth field can be matched by
^L1(?:,(\d+)){3}
The fifth field can be matched by
^L1(?:,(\d+)){4}
etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.