2

I don't understand what I was doing wrong.

I tried the following (what I thought the simplest and most direct), but it would not match the filename string passed by outfile (Text/content_001_One.html):

switch( outfile ){
    case *.html :
        doctype="application/xhtml+xml" ;
        break;
    default : ;
} ;

I also tried (still without success):

switch( outfile ){
    case /*.html/ :
    case /*.html$/ :
    case /*[.]html/ :
        doctype="application/xhtml+xml" ;
        break;
    default : ;
} ;

I was forced to resort to this

n=split( outfile, pathName, "." ) ;
printf("\t\t Suffix of outfile => %s ...\n", pathName[n] ) | "cat 1>&2" ;
switch( pathName[n] ){
    case "html" :
        doctype="application/xhtml+xml" ;
        break;
    default : ;
} ;

I would prefer to use the outfile value directly instead of the workaround.

Can someone please show me what the correct form would be?

5
  • 3
    Recall that in RegEx (not file globbing) * means "zero or more of the previous character", you need .*\.html probably. Good luck.
    – shellter
    Commented Jul 3, 2023 at 22:01
  • 2
    * as the first character in a regexp is undefined behavior per POSIX so YMMV with what any awk would do with that.
    – Ed Morton
    Commented Jul 3, 2023 at 22:18
  • 1
    You are referring a glob pattern. Same concept, although it is not, specifically, a "regular expression pattern".
    – Reilas
    Commented Jul 4, 2023 at 2:51
  • 1
    If you want to match a string that ends in foo just write foo$. Adding .* in a regexp (or * in a globbing pattern) in front of foo is pointless unless you wanted to capture the matching string to do something with it, which you don't.
    – Ed Morton
    Commented Jul 4, 2023 at 11:07
  • Thank you all for your comments. Much appreciated. Commented Jul 5, 2023 at 20:35

1 Answer 1

3

For a string that ends in .html one viable regex is /\.html$/, eg:

switch( outfile ){
    case /\.html$/ :
        doctype="application/xhtml+xml" ;
        break;
    default : ;
} ;
1
  • It seems that I don't fully understand the difference between regexp and globbing. I need to dig into that and get it sorted out in my mind for good. Commented Jul 5, 2023 at 20:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.