RegExp negative match not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting RegExp negative match not working
# 1  
Old 08-21-2006
RegExp negative match not working

or I don't know how to make it work ...
Hello
im trying to build regexp that will match me single string or function call inside of brackets
for example I have :

<% myFunction("blah",foo) %>
or
<% myVar %>

and not match :
<% if(myFunction("blah",foo)==1) %>
or
<% while(myvar < 3){ %>

I tried to make it work with this regexp with no much lock :

<%\s* (\w+[^=<>*]) \s* %>
or
<%\s* (.*[^=<>*]) \s* %>
# 2  
Old 08-22-2006
Some time ago...

Hi Umen,

I did something similar sometime ago in perl here's the final code that takes my array and does the replace throughout the opened file:

Code:
foreach my $key (keys %enabled_yn) {
 $enabled_yn{$key} =~ chomp;
 $enabled_yn{$key} =~ s/Y/\<b\>\<font color=\"yellow\"\>Y\<\/font\>\<\/b\>/;
 $enabled_yn{$key} =~ s/ALL/\<b\>\<font color=\"yellow\"\>ALL\<\/font\>\<\/b\>/;
}


open (ZMIO, "/opt/apache/cgi-bin/html_templates/zmio.htp") or "Couldn't open file $!";
read (ZMIO,$html,-s "/opt/apache/cgi-bin/html_templates/zmio.htp") or "Couldn't open file $!";

      $html =~ s/%(\w+)%/$enabled_yn{$1}/g;

print $html;

The penultimate line starting $html is where the regexp is taking place.

HTH,

Cheers,
pondlife.

Last edited by blowtorch; 08-22-2006 at 07:35 AM.. Reason: removed link
# 3  
Old 08-22-2006
Hello and thanks for the fast reply , but can you please explain me what you did ?
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk or sed to print the character from the previous line after the regexp match

Hi All, I need to print the characters in the previous line just before the regular expression match Please have a look at the input file as attached I need to match the regular expression ^ with the character of the previous like and also the pin numbers and the output file should be like... (6 Replies)
Discussion started by: kshitij
6 Replies

2. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies

3. Shell Programming and Scripting

Match working for some but not all

I am not sure why the script below seems to pull the correct values for most, but not all. Basically what is supposed to result is the $1 value in genes.txt is matched to the $3 value in RefSeqGene.txt and the value in 6 field is copied. In the output below that is the case most of the time but... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

Question on TCL regexp and match

Hello everyone, I'm new in tcl scripting. I'm currently studying a tcl script and came across this line: regexp {(\d+)(\S?)} $opts match opt swi According to my understanding, this line means to search in the opts variable for one or more digit, followed by a non-whitespace character... (2 Replies)
Discussion started by: mar85
2 Replies

5. UNIX for Dummies Questions & Answers

Grep Regexp not working correctly

Consider the following code: grep -o -e '^STEAM_::\d+$' workfile3.tmp A sample format of a valid string for the regexp would be: STEAM_0:1:12345678 Here is an example line from the workfile3.tmp file: 465:L 01/02/2012 - 00:05:33: "Spartan1-1-7<8><STEAM_0:1:47539638><>" connected No... (2 Replies)
Discussion started by: spinner0205
2 Replies

6. UNIX for Dummies Questions & Answers

regexp: match string that contains list of chars

Hi, I'm curious about how to do a very simple thing with regular expressions that I'm unable to figure out. If I want to find out if a string contains 'a' AND 'b' AND 'c' it can be very easily done with grep: echo $STRING|grep a|grep b|grep c but, how would you do that in a single... (9 Replies)
Discussion started by: jimcanoa
9 Replies

7. Shell Programming and Scripting

perl regexp: no match across newlines

Hi. Here's a tricky one (at least to me): I have a file named theFile.txt (UTF-8) that contains the following: a b cWhen I execute perl -pe 's|a.*c|d|sg' theFile.txtin bash 3.2 on MAC OS X 10.6, I get no match, i.e. the result is a b cagain. Any clues why? (2 Replies)
Discussion started by: BatManWSL
2 Replies

8. Shell Programming and Scripting

Regexp to match all characters including "?"

Hi everyone, I'm almost tearing my hairs to find a valid regexp which will match EVERY character in a string, including the question mark! Specifically I need to match a string which contains the word (example) "stringtobematched" at the end of it. Everyone would suggest this: ... (4 Replies)
Discussion started by: lycaon
4 Replies

9. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies
Login or Register to Ask a Question