Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: RegEx question

by ikegami (Pope)
on Dec 21, 2017 at 22:14 UTC ( #1206003=note: print w/replies, xml ) Need Help??

in reply to RegEx question

If you mean "something that isn't bank" (as you said),

/ ^ (?: .{0,3} | (?!bank}.{4} | .{5,} ) nova [ ] scotia (?: .{0,3} | (?!bank}.{4} | .{5,} ) $ /sx


/ ^ (?: | [^b].* | b[^a].* | ba[^n].* | ban[^k].* | bank.+ ) nova [ ] scotia (?: | [^b].* | b[^a].* | ba[^n].* | ban[^k].* | bank.+ ) $ /sx

If you mean "something that doesn't contain bank",

/ ^ (?: (?!bank). )* nova [ ] scotia (?: (?!bank). )* $ /sx

Replies are listed 'Best First'.
Re^2: RegEx question
by vit (Friar) on Dec 21, 2017 at 22:41 UTC
    Is it possible to write it without Pattern Modifiers? In other words without /sx

      Sure, just squish it all together (untested)
          /^(?:(?!bank).)*nova[ ]scotia(?:(?!bank).)*$/
      and remember that  . (dot) no longer "matches all." But why would you want to?

      Update: Actually, you no longer need the character class (update: because without  /x a space is a literal space):
          /^(?:(?!bank).)*nova scotia(?:(?!bank).)*$/
      and if you just gotta get rid of that last space:
      (both still untested).

      Give a man a fish:  <%-{-{-{-<

        Because I need it for both Perl and Java. Looks like this works, thank you very much !!!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1206003]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2018-02-25 22:07 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (315 votes). Check out past polls.