Viewed   116 times

I want all CSV files in a directory, so I use

glob('my/dir/*.CSV')

This however doesn't find files with a lowercase CSV extension.

I could use

glob('my/dir/*.{CSV,csv}', GLOB_BRACE);

But is there a way to allow all mixed case versions? Or is this just a limitation of glob() ?

 Answers

1

Glob patterns support character ranges:

glob('my/dir/*.[cC][sS][vV]')
Saturday, October 29, 2022
3

Values of attributes must be case-sensitive.

You can use arbitrary regular expression to select an element:

#!/usr/bin/env python
from lxml import html

doc = html.fromstring('''
    <meta name="Description">
    <meta name="description">
    <META name="description">
    <meta NAME="description">
''')
for meta in doc.xpath('//meta[re:test(@name, "^description$", "i")]',
                      namespaces={"re": "http://exslt.org/regular-expressions"}):
    print html.tostring(meta, pretty_print=True),

Output:

<meta name="Description">
<meta name="description">
<meta name="description">
<meta name="description">
Sunday, October 2, 2022
1

ZSH:

$ unsetopt CASE_GLOB

Or, if you don't want to enable case-insensitive globbing in general, you can activate it for only the varying part:

$ print -l (#i)(somelongstring)*

This will match any file that starts with "somelongstring" (in any combination of lower/upper case). The case-insensitive flag applies for everything between the parentheses and can be used multiple times. Read the manual zshexpn(1) for more information.

UPDATE Almost forgot, you have to enable extendend globbing for this to work:

setopt extendedglob
Saturday, December 10, 2022
 
5

Just use preg_split() and pass the flag i for case-insensitivity:

$keywords = preg_split("/your delimiter/i", $text);

Also make sure your delimiter which you pass to preg_split() doesn't cotain any sepcial regex characters. Otherwise make sure you escape them properly or use preg_quote().

Saturday, November 19, 2022
 
2

My fault! I guess I tried

find -ipath 'projects/insanewebproject' 

but the trick here is that I must use

find -ipath './projects/insanewebproject'

That ./ does the change. Thanks!.

man says -path is more portable than -wholename

if you expect only one result, you can add | head -n1, cause that way head kill pipe when it fills its buffer, which is only one line length

find -ipath './projects/insanewebproject'| head -n1
Thursday, November 3, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :