Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: input foo, output '[F|f][O|o][O|o]'?



I do not think you will find a way to do this. All regex engines (precisely, programs that are using them) I know support a way to set case sensitivity for the whole regular expression and some support toggling this for a part of regular expression. In grep this is an -i switch, for vim it is either /i or \c/\C, for sed this is /i, for PCRE and perl this is additionally (?i) "atom" (additionally to other ways of toggling the behavior which are highly dependent on programs embedding PCRE; for perl this is usual /i flag). Even zsh globs do support (#i).

By the way, what regex engine is your output for? Any I am aware of parse "[N|n]" as "either one of three characters: N, n, or pipe".

I am also assuming XY problem here: what for do you need such conversion? You should consider lowercasing the tested string if nothing like -i is available.

01.07.13, 22:12, "TJ Luoma" <luomat@xxxxxxxxx>":
> 
> 
> Before I reinvent the wheel, I thought I'd ask if someone already had 
> (or knew of) a way to take a string of characters and output a 'case 
> insensitive' regex version.
> 
> For example, if I input 'CrashPlan' I'd want to get out 
> [C|c][R|r][A|a][S|s][H|h][P|p][L|l][A|a][N|n]
> 
> (Input will usually be ASCII letters, with an occasional number and 
> perhaps the occasional '-' or '_' but doesn't need to handle anything 
> more complex than that.)
> 
> I tried Google but found it pretty impossible to make a good query for 
> something like this.
> 
> TjL



Messages sorted by: Reverse Date, Date, Thread, Author