Hi i am trying to match a string against a pattern
this is the possible string
signal CS, NS, dl: stateType := writeOrRead0;
signal CS, pS : stateType := writeOrRead0;
signal dS : stateType := writeOrRead0;
i am only concerned with the pattern as far as the first colon.
but the number of signals define can be more than one it could be three or four even
this is the regular expression i have
^signal\\s*(\\w+),*\\s*(\\w+)\\s*:
it will pick up the second two signal but and for the second one it picks up CS and pS and but the d and S in the next signal when i use
matcher.group()
come up seperately
Can anyone give me an expression that will pick up all signal names whether there is one two three or more?
If you want to have a group per signal name, that’s not possible (unless you have an upper bound for the number of signals, then you could write out the entire thing, but it’d be very ugly).
So you’ll have to live with one group containing the names, comma separated. Then you can post-process that to get out the real signal names.
That would give something like
(Note that I didn’t escape it as a Java String.)
group 1 are your names.