help-bash
[Top][All Lists]
Advanced

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

Re: What is wrong with a regex?


From: Koichi Murase
Subject: Re: What is wrong with a regex?
Date: Sat, 4 Feb 2023 12:58:52 +0900

2023年2月4日(土) 12:44 Peng Yu <pengyu.ut@gmail.com>:
> $ f=row.txt; [[ $f =~ ^row([0-9]*)(\|_x)[.]txt$ ]]; echo $?
> 1

You need to write (|_x) instead of (\|_x). In the conditional command
[[ ... ]], the character `|' loses the original meaning of the pipe
operator, so you can directly specify it without quoting. If you quote
it as \|, it becomes a regular expression that matches a literal
single character `|'.

$ [[ '|' =~ \| ]]; echo $?
0



reply via email to

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