Friday, 15 February 2013

javascript - Matching multiple optional characters depending on each other -


I want to match all valid prefixes with the other characters with the option , so that

sub part.
  • Options / ABC / DF
    • Match ABC / DEF Options .
    • The subt / abc / def match does not match or only matches the sub section, not t .

    My current reggae is / ^ s (u (b (s (t (u (te?)?))?)?)?)?)?)? )?)? / , which works, though it seems a little verbose.

    Is there any better (less, verbose) to do this?

  • You can use two-step reggae

    1. Use the simple pattern to find the first word of the subject ^ (\ w +)
    2. Use the word extracted from step 1 as if your regex pattern is the word option ^ subs against

    No comments:

    Post a Comment