2

my problem is, I try to strip a string at a start of a variable. I have done shopt -s exglob to get extended pattern matching.

    a="HelloDolly"
    echo "${a#[A-Z]+([a-z])}"

I thought that +([a-z]) mean as much lower case letter as possible. And that [A-Z]+([a-z]) should match Hello

should return Dolly but I get lloDolly back. If give / instead # a try

    echo "${a/[A-Z]+([a-z])}"

I get back nothing. Looks like the Parameter Expansions is caseinsensitive.

Thanks everybody who could give me an hint.

4

1 に答える 1

1

# を 1 つ使用すると、可能な限り短い一致が得られます。"He" は、大文字 1 文字と小文字 1 文字以上の最短一致です。double # に切り替えて、可能な限り最長の一致 "Hello" を取得します

echo "${a##[A-Z]+([a-z])}"

文字範囲のロケールベースの解釈に関する問題を回避するには、代わりに文字クラスを使用します。

echo "${a##[[:upper:]]+([[:lower:]])}"
于 2012-08-18T18:49:48.580 に答える