help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to match the less-than symbol in regex?


From: Peng Yu
Subject: Re: How to match the less-than symbol in regex?
Date: Tue, 17 Mar 2020 19:49:42 -0500

On 3/17/20, Daniel Mills <address@hidden> wrote:
> On Tue, Mar 17, 2020 at 8:27 PM Peng Yu <address@hidden> wrote:
>
>> Hi,
>>
>> I am not able to match "<" in the regex. I am not sure what is wrong.
>> Could anybody show me how to match "<" in regex? Thanks.
>>
>> $ [[ '9<' =~ '^([0-9]+)<$' ]]; echo $?
>> 1
>>
>> --
>> Regards,
>> Peng
>>
>>
> Quoted things on the right side are treated as literals. To get around this
> issue,
> put the regex in a variable, and use an unquoted expansion.
>
> re='^([0-9]+)<$'; [[ '0<' =~ $re ]]; echo $?

$ [[ '9<' =~ ^([0-9]+)<$ ]]
-bash: syntax error in conditional expression: unexpected token `<'
-bash: syntax error near `^([0-9]+)<$'

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]