What we have:
In a previous question, the following pattern was suggested to recognize lines matching a pattern in bash, and extract parts of that line into shell variables:
re='^\[([[:digit:]:]+)\] \[Server thread/INFO\]: ([^[:space:]]+) entered area ~ ([^[:space:]]+) - [(]PvP[)] ~'
line='[18:51:10] [Server thread/INFO]: Tester121 entered area ~ Wilderness - (PvP) ~'
if [[ $line =~ $re ]]; then
time=${BASH_REMATCH[1]}
player=${BASH_REMATCH[2]}
area=${BASH_REMATCH[3]}
fi
However, that code doesn't work with a different where the content being matched can contain spaces. Consider the following less-simplified format:
re='???'
line='[19:27:14] [Server thread/INFO]: Tester121 entered area ~ City - Leader Tester777 - (No PvP) ~'
if [[ $line =~ $re ]]; then
time=${BASH_REMATCH[1]}
player=${BASH_REMATCH[2]}
area=${BASH_REMATCH[3]}
#leader="Tester777"
leader=${BASH_REMATCH[4]}
#pvp="No PvP"
pvp=${BASH_REMATCH[5]}
fi
What should be the re
for it? I am new to regex and try to learn.