Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Simple regex help

Expand Messages
  • merlyn@stonehenge.com
    ... da5id Just wondering how to search a string for non word characters that da5id aren t spaces... da5id W is for a non-word character, s would find a
    Message 1 of 2 , Nov 27, 2006
    • 0 Attachment
      >>>>> "da5id" == da5id <da5id@...> writes:

      da5id> Just wondering how to search a string for non word characters that
      da5id> aren't spaces...
      da5id> \W is for a non-word character, \s would find a space, just wondering
      da5id> how to put that together in a regex...

      You can only "or" together in a char class (this OR that).
      But you want to "and". Luckily, DeMorgan's laws teaches us
      that the following are equivalent:

      (this AND that)
      NOT (NOT this OR NOT that)

      so it's just a matter of writing it out. You want:

      (non-word AND non-space)

      which demorgan says is:

      NOT (NOT non-word OR NOT non-space)

      and reducing the nots:

      NOT (word OR space)

      and writing that in regex talk:

      [ ^ \w \s ]

      and removing the spacing:

      [^\w\s]

      There ya go. All the chars that are neither word nor space.

      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
    Your message has been successfully submitted and would be delivered to recipients shortly.