Could you please help in creating a regular expression which can validate the following string of below format in Java?
The string contains key and value separated by a colon(:). These key and value pairs are further separated by either an & or | symbol.
"key:value"|"key:value"&"key:value"|"key:value"
Here key is string which can have only alphabets. Here value is alphanumeric.
("\w+:\w+"[\|\&]?)+
This will match in order:
"
1 or more word characters [a-zA-Z0-9]
:
1 or more word characters [a-zA-Z0-9]
"
0 or 1 | or & character
and this, 1 or more times
And I agree with J. Chomel, this is not higher level regex so with a little bit of research, you should have been able to figure it out yourself.
Have a look at these websites for more info on regex:
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.