Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. negation of an expression

negation of an expression

Scheduled Pinned Locked Moved Regular Expressions
regexquestion
3 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vijjuuu
    wrote on last edited by
    #1

    i thought it would be simpler, however i wasnt able to get regular expression for the below. i want to extract the words which are not in a particular pattern. say in the below sentence clicking the (Run Match) button (or F5) to see what (happens). i want to extract all the words which are not defined in brackets (). so the output will be clicking the button to see what below is expression which i defined. it is not working. can any one point out the mistake in the expression ? (?!\(\w+\))

    Richard DeemingR B 2 Replies Last reply
    0
    • V Vijjuuu

      i thought it would be simpler, however i wasnt able to get regular expression for the below. i want to extract the words which are not in a particular pattern. say in the below sentence clicking the (Run Match) button (or F5) to see what (happens). i want to extract all the words which are not defined in brackets (). so the output will be clicking the button to see what below is expression which i defined. it is not working. can any one point out the mistake in the expression ? (?!\(\w+\))

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      You haven't mentioned which language you're using. Different languages have different implementations of Regular Expressions, which support different features. The following should work in .NET:

      (?
      This uses zero-width negative assertions[^] to ensure that the word doesn't start with an opening parenthesis, or end with a closing parenthesis.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined."
      ** - Homer**

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • V Vijjuuu

        i thought it would be simpler, however i wasnt able to get regular expression for the below. i want to extract the words which are not in a particular pattern. say in the below sentence clicking the (Run Match) button (or F5) to see what (happens). i want to extract all the words which are not defined in brackets (). so the output will be clicking the button to see what below is expression which i defined. it is not working. can any one point out the mistake in the expression ? (?!\(\w+\))

        B Offline
        B Offline
        bulrush400
        wrote on last edited by
        #3

        How about if we just drop all the words in (parens) and display what's left? #!/usr/bin/perl use strict; use warnings; my(@a,@b,$i,$j,$k,$s,$t); my(@out,$ins,$outs); $ins="clicking the (Run Match) button (or F5) to see what (happens). "; print "\n"; $outs=$ins; $outs=~s/\(.+?\)//g; $outs=undupespace($outs); print "$outs\n"; exit; # Exit main pgm. ################################################################### sub undupespace # Remove dupe spaces. Max 1 consecutive space. {my($l)=@_; $l=~s/ {2,}/ /g; return $l; # undupespace } Output: clicking the button to see what .

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups