negation of an expression
-
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+\))
-
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+\))
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** -
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+\))
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 .