How would you use multiple delimiters or a single delimiter to detect and separate out different string matches?
For example, I use a Scanner to parse in the following string:
MrsMarple=new Person(); MrsMarple.age=30;
I would like to separate out this string to determine, in sequence, when a new person is being created and when their age is being set. I also need to know what the age is being set to.
There can be anything between and/or either side of these arguments (there doesn’t necessarily have to be a space between them, but the semi-colon is required). The “MrsMarple” could be any word. I would also prefer any arguments following a “//” (two slashes) on the same line to be ignored but that’s optional.
If you can think of a simple alternative to using regex I’m more than willing to consider it.
I might try a simple split/loop approach.
Given
String input = "MrsMarple=new Person(); MrsMarple.age=30;":with judicious use of
String.trim()and or other simple tools.