PDA

View Full Version : Matching quotes using QregExp/QRegularExpression



eivindmu
30th May 2018, 08:14
Hi,

I am trying to create a text highlighter in Qt for bash scripts using regular expressions, which I am fairly new too. My problem is seen in the code below, where I want to color all text from the first quote until the last quote before I write to file.
I also want to color the content between the quotes in the variable "Var" and the last echo, so basically the same highlighting as when opening a bash script in Gedit.


echo "
while IFS=\"\" read -r line || [[ -n \$line ]]; do
running=\$(netstat -an | grep :\$line | wc -l)
sleep \"1\"
if [ \"\$running\" = \"0\" ]
then
fi

done < \"\$file\"" >> $FILE

Var="Test"

echo ""

So far I have a regular expression looking like this:
["](((?:[^"]|["](?!\s*>))+))["]
When I test this I paste it in regexr.com and it works fine for the first echo. For the variable and the last echo it colors everything from the first quote after "Var=" until the last quote after echo.

Can anyone help me complete my expression, and also how to be able to use it as a QRegExp or QRegularExpression?