Reputation: 55
I want a regex to match an enumeration of versions separated by semicolons. Also there may not be mentioned a version.
Examples of input:
12.1.01;;;1.3.400;12-3;5;;;;;;4,5
12.5
;;;13,7;;15-12.300
At least one version should be mentioned between semicolons. Number of versions can be any.
Currently this regex seems to do what I want:
regex="^\;*([0-9]+([\.\,\-]{1}[0-9]+)*)+(\;|([0-9]+([\.\,\-]{1}[0-9]+)*))*$"
Other solutions?
Upvotes: 0
Views: 76
Reputation: 744
This pattern matches a line if it is valid
/^(;*((\d+)\.)*?(\d+);*)*$/
This pattern matches everything not ;
/[^;]+/g
This pattern matches a version:
/(\d+\.)*\d+/
Upvotes: 0
Reputation: 490
If you are looking for anything inside the semicolons, the regex
([^;]+)
should do the trick. It will match as long sequences as possible of symbols that aren't ;
The regex:
([^;\n\r]+)
will also separate version names that are on different rows without any semicolons between them.
Upvotes: 2
Reputation: 199
I would use a for to iterate over the versions, something like this:
IFS=';'
for x in string
do
version = $x
done
Just like a manual split of classic programming languages.
Upvotes: -1