regex - Java regular expressions for specific name\value format -
i'm not familiar yet java regular expressions. want validate string has following format:
string input = "[name1 value1];[name2 value2];[name3 value3];"; namei , valuei strings should contain characters expect white-space.
i tried expression:
string regex = "([\\s*\\s\\s*];)*"; but if call matches() false string.
what's best regular expression it?
this trick:
(?:\[\w.*?\s\w.*?\];)* if want match 3 of these, replace * @ end {3}.
explanation:
(?:: start of non-capturing group\[: escapes[sign meta-character in regex. allows used matching.\w.*?: lazily matches word character[a-z][a-z][0-9]_. lazy matching means attempts match character few times possible, in case meaning when stop matching once finds following\s.\s: matches 1 whitespace\]: see\[;: matches 1 semicolon): end of non-capturing group*: matches number of contained in preceding non-capturing group.
Comments
Post a Comment