How to expand the condition? 
Author Message
 How to expand the condition?

My simple 'txt2html' script is getting better every day...

Thanks to this list, and to those who cure it. :)

I have a condition which checks for .JPG files.

I have 2 questions:

1. how to ignore uppercase/lowercase?
2. how to expand it into checking JPG, GIF, PNG, etc.?
(I did it with copying the above line, but that's not elegant...)

the code:

  gsub(/[-._a-zA-Z0-9]+jpg/, "<img src=\"&\" alt=\"&\">")

--
Mihaly Gyulai

http://www.*-*-*.com/

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Tue, 18 Feb 2003 16:31:32 GMT  
 How to expand the condition?

Quote:

> I have a condition which checks for .JPG files.
> I have 2 questions:
> 1. how to ignore uppercase/lowercase?

Some ideas to look thru in the manuals:

- for gawk, global variable IGNORECASE (notice it affects ALL
  matchings and comparisons)

- use explicit regexp with both cases: /[Jj][Pp][Gg]/...

- in other contexts (not this of yours) a possible kluge is
  to use toupper() or tolower() in the string to be compared

Quote:
> 2. how to expand it into checking JPG, GIF, PNG, etc.?
> (I did it with copying the above line, but that's not elegant...)

> the code:

>   gsub(/[-._a-zA-Z0-9]+jpg/, "<img src=\"&\" alt=\"&\">")

- A possible idea is to use ( | ) for alternatives in regexp:
  /[-._a-zA-Z0-9]+\.(jpg|gif)/
  or
  /[-._a-zA-Z0-9]+\.([Jj][Pp][Gg]|[Gg][Ii][Ff])/
  Notice that you might need to perform more than one such
  substitutions on the same line.

--
  All true believers shall break their eggs at the convenient end.



Tue, 18 Feb 2003 17:43:58 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Splitting 'and' conditions into multiple conditions

2. Order of evaluation of conditions in a combined condition

3. Order of evaluation of conditions in a combined condition/PMAP

4. Pre-condition vs. Post-condition

5. Pre-condition vs. Post-condition

6. Pre-condition vs Post-condition

7. "BIG E vs little e", was pre-condition vs post-condition

8. pre-condition vs post-condition

9. Default initial values (was: Pre-condition vs. Post-condition)

10. Expanded Icon in TreeView

11. Using expand and filling rows and columns with sums

12. APL Expand in J.

 

 
Powered by phpBB® Forum Software