I would like to split a Simulink path that looks like this: "a/b/c//d". It should split to [a,b,c/d]. How would the regular expression look like?
Thanks and regards
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This should do the trick:
The regular expression can be understood as follows: the first part matches any not-slashes (
[^/]) OR double-slashes, giving the piece([^/]|//). We want any number of those, so we need a*, followed by EITHER a slash-then-not-slash OR the end of the string (/[^/]|$). We use the lookahead operator(?= ... )do do that.The strrep is to replace
//with/in the result. Maybe that can be done in the same call toregexp, but it’s complicated enough already for my taste.